001-squashfs.patch 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082
  1. Index: linux-2.4.35.4/fs/Config.in
  2. ===================================================================
  3. --- linux-2.4.35.4.orig/fs/Config.in
  4. +++ linux-2.4.35.4/fs/Config.in
  5. @@ -51,6 +51,14 @@ if [ "$CONFIG_JFFS2_FS" = "y" -o "$CONFI
  6. int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
  7. fi
  8. tristate 'Compressed ROM file system support' CONFIG_CRAMFS
  9. +tristate 'Squashed file system support' CONFIG_SQUASHFS
  10. +if [ "$CONFIG_SQUASHFS" = "y" -o "$CONFIG_SQUASHFS" = "m" ] ; then
  11. +bool 'Additional options for memory constrained systems ' CONFIG_SQUASHFS_EMBEDDED
  12. +fi
  13. +if [ "$CONFIG_SQUASHFS_EMBEDDED" = "y" ] ; then
  14. +int 'Number of fragments cached' CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE 3
  15. +bool 'Use Vmalloc rather than Kmalloc' CONFIG_SQUASHFS_VMALLOC
  16. +fi
  17. bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
  18. define_bool CONFIG_RAMFS y
  19. Index: linux-2.4.35.4/fs/Makefile
  20. ===================================================================
  21. --- linux-2.4.35.4.orig/fs/Makefile
  22. +++ linux-2.4.35.4/fs/Makefile
  23. @@ -65,6 +65,7 @@ subdir-$(CONFIG_REISERFS_FS) += reiserfs
  24. subdir-$(CONFIG_DEVPTS_FS) += devpts
  25. subdir-$(CONFIG_SUN_OPENPROMFS) += openpromfs
  26. subdir-$(CONFIG_BEFS_FS) += befs
  27. +subdir-$(CONFIG_SQUASHFS) += squashfs
  28. subdir-$(CONFIG_JFS_FS) += jfs
  29. subdir-$(CONFIG_XFS_FS) += xfs
  30. Index: linux-2.4.35.4/fs/squashfs/inode.c
  31. ===================================================================
  32. --- /dev/null
  33. +++ linux-2.4.35.4/fs/squashfs/inode.c
  34. @@ -0,0 +1,2028 @@
  35. +/*
  36. + * Squashfs - a compressed read only filesystem for Linux
  37. + *
  38. + * Copyright (c) 2002, 2003, 2004, 2005, 2006
  39. + * Phillip Lougher <[email protected]>
  40. + *
  41. + * This program is free software; you can redistribute it and/or
  42. + * modify it under the terms of the GNU General Public License
  43. + * as published by the Free Software Foundation; either version 2,
  44. + * or (at your option) any later version.
  45. + *
  46. + * This program is distributed in the hope that it will be useful,
  47. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  48. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49. + * GNU General Public License for more details.
  50. + *
  51. + * You should have received a copy of the GNU General Public License
  52. + * along with this program; if not, write to the Free Software
  53. + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  54. + *
  55. + * inode.c
  56. + */
  57. +
  58. +#include <linux/types.h>
  59. +#include <linux/squashfs_fs.h>
  60. +#include <linux/module.h>
  61. +#include <linux/errno.h>
  62. +#include <linux/slab.h>
  63. +#include <linux/fs.h>
  64. +#include <linux/smp_lock.h>
  65. +#include <linux/locks.h>
  66. +#include <linux/init.h>
  67. +#include <linux/dcache.h>
  68. +#include <linux/wait.h>
  69. +#include <linux/zlib.h>
  70. +#include <linux/blkdev.h>
  71. +#include <linux/vmalloc.h>
  72. +#include <asm/uaccess.h>
  73. +#include <asm/semaphore.h>
  74. +
  75. +#include "squashfs.h"
  76. +
  77. +static struct super_block *squashfs_read_super(struct super_block *, void *, int);
  78. +static void squashfs_put_super(struct super_block *);
  79. +static int squashfs_statfs(struct super_block *, struct statfs *);
  80. +static int squashfs_symlink_readpage(struct file *file, struct page *page);
  81. +static int squashfs_readpage(struct file *file, struct page *page);
  82. +static int squashfs_readpage4K(struct file *file, struct page *page);
  83. +static int squashfs_readdir(struct file *, void *, filldir_t);
  84. +static struct dentry *squashfs_lookup(struct inode *, struct dentry *);
  85. +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode);
  86. +static long long read_blocklist(struct inode *inode, int index,
  87. + int readahead_blks, char *block_list,
  88. + unsigned short **block_p, unsigned int *bsize);
  89. +
  90. +static z_stream stream;
  91. +
  92. +static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
  93. +
  94. +static unsigned char squashfs_filetype_table[] = {
  95. + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
  96. +};
  97. +
  98. +static struct super_operations squashfs_ops = {
  99. + .statfs = squashfs_statfs,
  100. + .put_super = squashfs_put_super,
  101. +};
  102. +
  103. +SQSH_EXTERN struct address_space_operations squashfs_symlink_aops = {
  104. + .readpage = squashfs_symlink_readpage
  105. +};
  106. +
  107. +SQSH_EXTERN struct address_space_operations squashfs_aops = {
  108. + .readpage = squashfs_readpage
  109. +};
  110. +
  111. +SQSH_EXTERN struct address_space_operations squashfs_aops_4K = {
  112. + .readpage = squashfs_readpage4K
  113. +};
  114. +
  115. +static struct file_operations squashfs_dir_ops = {
  116. + .read = generic_read_dir,
  117. + .readdir = squashfs_readdir
  118. +};
  119. +
  120. +static struct inode_operations squashfs_dir_inode_ops = {
  121. + .lookup = squashfs_lookup
  122. +};
  123. +
  124. +static struct buffer_head *get_block_length(struct super_block *s,
  125. + int *cur_index, int *offset, int *c_byte)
  126. +{
  127. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  128. + unsigned short temp;
  129. + struct buffer_head *bh;
  130. +
  131. + if (!(bh = sb_bread(s, *cur_index)))
  132. + goto out;
  133. +
  134. + if (msblk->devblksize - *offset == 1) {
  135. + if (msblk->swap)
  136. + ((unsigned char *) &temp)[1] = *((unsigned char *)
  137. + (bh->b_data + *offset));
  138. + else
  139. + ((unsigned char *) &temp)[0] = *((unsigned char *)
  140. + (bh->b_data + *offset));
  141. + brelse(bh);
  142. + if (!(bh = sb_bread(s, ++(*cur_index))))
  143. + goto out;
  144. + if (msblk->swap)
  145. + ((unsigned char *) &temp)[0] = *((unsigned char *)
  146. + bh->b_data);
  147. + else
  148. + ((unsigned char *) &temp)[1] = *((unsigned char *)
  149. + bh->b_data);
  150. + *c_byte = temp;
  151. + *offset = 1;
  152. + } else {
  153. + if (msblk->swap) {
  154. + ((unsigned char *) &temp)[1] = *((unsigned char *)
  155. + (bh->b_data + *offset));
  156. + ((unsigned char *) &temp)[0] = *((unsigned char *)
  157. + (bh->b_data + *offset + 1));
  158. + } else {
  159. + ((unsigned char *) &temp)[0] = *((unsigned char *)
  160. + (bh->b_data + *offset));
  161. + ((unsigned char *) &temp)[1] = *((unsigned char *)
  162. + (bh->b_data + *offset + 1));
  163. + }
  164. + *c_byte = temp;
  165. + *offset += 2;
  166. + }
  167. +
  168. + if (SQUASHFS_CHECK_DATA(msblk->sblk.flags)) {
  169. + if (*offset == msblk->devblksize) {
  170. + brelse(bh);
  171. + if (!(bh = sb_bread(s, ++(*cur_index))))
  172. + goto out;
  173. + *offset = 0;
  174. + }
  175. + if (*((unsigned char *) (bh->b_data + *offset)) !=
  176. + SQUASHFS_MARKER_BYTE) {
  177. + ERROR("Metadata block marker corrupt @ %x\n",
  178. + *cur_index);
  179. + brelse(bh);
  180. + goto out;
  181. + }
  182. + (*offset)++;
  183. + }
  184. + return bh;
  185. +
  186. +out:
  187. + return NULL;
  188. +}
  189. +
  190. +
  191. +SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
  192. + long long index, unsigned int length,
  193. + long long *next_index)
  194. +{
  195. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  196. + struct buffer_head *bh[((SQUASHFS_FILE_MAX_SIZE - 1) >>
  197. + msblk->devblksize_log2) + 2];
  198. + unsigned int offset = index & ((1 << msblk->devblksize_log2) - 1);
  199. + unsigned int cur_index = index >> msblk->devblksize_log2;
  200. + int bytes, avail_bytes, b = 0, k;
  201. + char *c_buffer;
  202. + unsigned int compressed;
  203. + unsigned int c_byte = length;
  204. +
  205. + if (c_byte) {
  206. + bytes = msblk->devblksize - offset;
  207. + compressed = SQUASHFS_COMPRESSED_BLOCK(c_byte);
  208. + c_buffer = compressed ? msblk->read_data : buffer;
  209. + c_byte = SQUASHFS_COMPRESSED_SIZE_BLOCK(c_byte);
  210. +
  211. + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
  212. + ? "" : "un", (unsigned int) c_byte);
  213. +
  214. + if (!(bh[0] = sb_getblk(s, cur_index)))
  215. + goto block_release;
  216. +
  217. + for (b = 1; bytes < c_byte; b++) {
  218. + if (!(bh[b] = sb_getblk(s, ++cur_index)))
  219. + goto block_release;
  220. + bytes += msblk->devblksize;
  221. + }
  222. + ll_rw_block(READ, b, bh);
  223. + } else {
  224. + if (!(bh[0] = get_block_length(s, &cur_index, &offset,
  225. + &c_byte)))
  226. + goto read_failure;
  227. +
  228. + bytes = msblk->devblksize - offset;
  229. + compressed = SQUASHFS_COMPRESSED(c_byte);
  230. + c_buffer = compressed ? msblk->read_data : buffer;
  231. + c_byte = SQUASHFS_COMPRESSED_SIZE(c_byte);
  232. +
  233. + TRACE("Block @ 0x%llx, %scompressed size %d\n", index, compressed
  234. + ? "" : "un", (unsigned int) c_byte);
  235. +
  236. + for (b = 1; bytes < c_byte; b++) {
  237. + if (!(bh[b] = sb_getblk(s, ++cur_index)))
  238. + goto block_release;
  239. + bytes += msblk->devblksize;
  240. + }
  241. + ll_rw_block(READ, b - 1, bh + 1);
  242. + }
  243. +
  244. + if (compressed)
  245. + down(&msblk->read_data_mutex);
  246. +
  247. + for (bytes = 0, k = 0; k < b; k++) {
  248. + avail_bytes = (c_byte - bytes) > (msblk->devblksize - offset) ?
  249. + msblk->devblksize - offset :
  250. + c_byte - bytes;
  251. + wait_on_buffer(bh[k]);
  252. + if (!buffer_uptodate(bh[k]))
  253. + goto block_release;
  254. + memcpy(c_buffer + bytes, bh[k]->b_data + offset, avail_bytes);
  255. + bytes += avail_bytes;
  256. + offset = 0;
  257. + brelse(bh[k]);
  258. + }
  259. +
  260. + /*
  261. + * uncompress block
  262. + */
  263. + if (compressed) {
  264. + int zlib_err;
  265. +
  266. + stream.next_in = c_buffer;
  267. + stream.avail_in = c_byte;
  268. + stream.next_out = buffer;
  269. + stream.avail_out = msblk->read_size;
  270. +
  271. + if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
  272. + ((zlib_err = zlib_inflate(&stream, Z_FINISH))
  273. + != Z_STREAM_END) || ((zlib_err =
  274. + zlib_inflateEnd(&stream)) != Z_OK)) {
  275. + ERROR("zlib_fs returned unexpected result 0x%x\n",
  276. + zlib_err);
  277. + bytes = 0;
  278. + } else
  279. + bytes = stream.total_out;
  280. +
  281. + up(&msblk->read_data_mutex);
  282. + }
  283. +
  284. + if (next_index)
  285. + *next_index = index + c_byte + (length ? 0 :
  286. + (SQUASHFS_CHECK_DATA(msblk->sblk.flags)
  287. + ? 3 : 2));
  288. + return bytes;
  289. +
  290. +block_release:
  291. + while (--b >= 0)
  292. + brelse(bh[b]);
  293. +
  294. +read_failure:
  295. + ERROR("sb_bread failed reading block 0x%x\n", cur_index);
  296. + return 0;
  297. +}
  298. +
  299. +
  300. +SQSH_EXTERN int squashfs_get_cached_block(struct super_block *s, char *buffer,
  301. + long long block, unsigned int offset,
  302. + int length, long long *next_block,
  303. + unsigned int *next_offset)
  304. +{
  305. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  306. + int n, i, bytes, return_length = length;
  307. + long long next_index;
  308. +
  309. + TRACE("Entered squashfs_get_cached_block [%llx:%x]\n", block, offset);
  310. +
  311. + while ( 1 ) {
  312. + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
  313. + if (msblk->block_cache[i].block == block)
  314. + break;
  315. +
  316. + down(&msblk->block_cache_mutex);
  317. +
  318. + if (i == SQUASHFS_CACHED_BLKS) {
  319. + /* read inode header block */
  320. + for (i = msblk->next_cache, n = SQUASHFS_CACHED_BLKS;
  321. + n ; n --, i = (i + 1) %
  322. + SQUASHFS_CACHED_BLKS)
  323. + if (msblk->block_cache[i].block !=
  324. + SQUASHFS_USED_BLK)
  325. + break;
  326. +
  327. + if (n == 0) {
  328. + wait_queue_t wait;
  329. +
  330. + init_waitqueue_entry(&wait, current);
  331. + add_wait_queue(&msblk->waitq, &wait);
  332. + set_current_state(TASK_UNINTERRUPTIBLE);
  333. + up(&msblk->block_cache_mutex);
  334. + schedule();
  335. + set_current_state(TASK_RUNNING);
  336. + remove_wait_queue(&msblk->waitq, &wait);
  337. + continue;
  338. + }
  339. + msblk->next_cache = (i + 1) % SQUASHFS_CACHED_BLKS;
  340. +
  341. + if (msblk->block_cache[i].block ==
  342. + SQUASHFS_INVALID_BLK) {
  343. + if (!(msblk->block_cache[i].data =
  344. + kmalloc(SQUASHFS_METADATA_SIZE,
  345. + GFP_KERNEL))) {
  346. + ERROR("Failed to allocate cache"
  347. + "block\n");
  348. + up(&msblk->block_cache_mutex);
  349. + goto out;
  350. + }
  351. + }
  352. +
  353. + msblk->block_cache[i].block = SQUASHFS_USED_BLK;
  354. + up(&msblk->block_cache_mutex);
  355. +
  356. + if (!(msblk->block_cache[i].length =
  357. + squashfs_read_data(s,
  358. + msblk->block_cache[i].data,
  359. + block, 0, &next_index))) {
  360. + ERROR("Unable to read cache block [%llx:%x]\n",
  361. + block, offset);
  362. + goto out;
  363. + }
  364. +
  365. + down(&msblk->block_cache_mutex);
  366. + wake_up(&msblk->waitq);
  367. + msblk->block_cache[i].block = block;
  368. + msblk->block_cache[i].next_index = next_index;
  369. + TRACE("Read cache block [%llx:%x]\n", block, offset);
  370. + }
  371. +
  372. + if (msblk->block_cache[i].block != block) {
  373. + up(&msblk->block_cache_mutex);
  374. + continue;
  375. + }
  376. +
  377. + if ((bytes = msblk->block_cache[i].length - offset) >= length) {
  378. + if (buffer)
  379. + memcpy(buffer, msblk->block_cache[i].data +
  380. + offset, length);
  381. + if (msblk->block_cache[i].length - offset == length) {
  382. + *next_block = msblk->block_cache[i].next_index;
  383. + *next_offset = 0;
  384. + } else {
  385. + *next_block = block;
  386. + *next_offset = offset + length;
  387. + }
  388. + up(&msblk->block_cache_mutex);
  389. + goto finish;
  390. + } else {
  391. + if (buffer) {
  392. + memcpy(buffer, msblk->block_cache[i].data +
  393. + offset, bytes);
  394. + buffer += bytes;
  395. + }
  396. + block = msblk->block_cache[i].next_index;
  397. + up(&msblk->block_cache_mutex);
  398. + length -= bytes;
  399. + offset = 0;
  400. + }
  401. + }
  402. +
  403. +finish:
  404. + return return_length;
  405. +out:
  406. + return 0;
  407. +}
  408. +
  409. +
  410. +static int get_fragment_location(struct super_block *s, unsigned int fragment,
  411. + long long *fragment_start_block,
  412. + unsigned int *fragment_size)
  413. +{
  414. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  415. + long long start_block =
  416. + msblk->fragment_index[SQUASHFS_FRAGMENT_INDEX(fragment)];
  417. + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET(fragment);
  418. + struct squashfs_fragment_entry fragment_entry;
  419. +
  420. + if (msblk->swap) {
  421. + struct squashfs_fragment_entry sfragment_entry;
  422. +
  423. + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
  424. + start_block, offset,
  425. + sizeof(sfragment_entry), &start_block,
  426. + &offset))
  427. + goto out;
  428. + SQUASHFS_SWAP_FRAGMENT_ENTRY(&fragment_entry, &sfragment_entry);
  429. + } else
  430. + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
  431. + start_block, offset,
  432. + sizeof(fragment_entry), &start_block,
  433. + &offset))
  434. + goto out;
  435. +
  436. + *fragment_start_block = fragment_entry.start_block;
  437. + *fragment_size = fragment_entry.size;
  438. +
  439. + return 1;
  440. +
  441. +out:
  442. + return 0;
  443. +}
  444. +
  445. +
  446. +SQSH_EXTERN void release_cached_fragment(struct squashfs_sb_info *msblk, struct
  447. + squashfs_fragment_cache *fragment)
  448. +{
  449. + down(&msblk->fragment_mutex);
  450. + fragment->locked --;
  451. + wake_up(&msblk->fragment_wait_queue);
  452. + up(&msblk->fragment_mutex);
  453. +}
  454. +
  455. +
  456. +SQSH_EXTERN struct squashfs_fragment_cache *get_cached_fragment(struct super_block
  457. + *s, long long start_block,
  458. + int length)
  459. +{
  460. + int i, n;
  461. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  462. +
  463. + while ( 1 ) {
  464. + down(&msblk->fragment_mutex);
  465. +
  466. + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS &&
  467. + msblk->fragment[i].block != start_block; i++);
  468. +
  469. + if (i == SQUASHFS_CACHED_FRAGMENTS) {
  470. + for (i = msblk->next_fragment, n =
  471. + SQUASHFS_CACHED_FRAGMENTS; n &&
  472. + msblk->fragment[i].locked; n--, i = (i + 1) %
  473. + SQUASHFS_CACHED_FRAGMENTS);
  474. +
  475. + if (n == 0) {
  476. + wait_queue_t wait;
  477. +
  478. + init_waitqueue_entry(&wait, current);
  479. + add_wait_queue(&msblk->fragment_wait_queue,
  480. + &wait);
  481. + set_current_state(TASK_UNINTERRUPTIBLE);
  482. + up(&msblk->fragment_mutex);
  483. + schedule();
  484. + set_current_state(TASK_RUNNING);
  485. + remove_wait_queue(&msblk->fragment_wait_queue,
  486. + &wait);
  487. + continue;
  488. + }
  489. + msblk->next_fragment = (msblk->next_fragment + 1) %
  490. + SQUASHFS_CACHED_FRAGMENTS;
  491. +
  492. + if (msblk->fragment[i].data == NULL)
  493. + if (!(msblk->fragment[i].data = SQUASHFS_ALLOC
  494. + (SQUASHFS_FILE_MAX_SIZE))) {
  495. + ERROR("Failed to allocate fragment "
  496. + "cache block\n");
  497. + up(&msblk->fragment_mutex);
  498. + goto out;
  499. + }
  500. +
  501. + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
  502. + msblk->fragment[i].locked = 1;
  503. + up(&msblk->fragment_mutex);
  504. +
  505. + if (!(msblk->fragment[i].length = squashfs_read_data(s,
  506. + msblk->fragment[i].data,
  507. + start_block, length, NULL))) {
  508. + ERROR("Unable to read fragment cache block "
  509. + "[%llx]\n", start_block);
  510. + msblk->fragment[i].locked = 0;
  511. + goto out;
  512. + }
  513. +
  514. + msblk->fragment[i].block = start_block;
  515. + TRACE("New fragment %d, start block %lld, locked %d\n",
  516. + i, msblk->fragment[i].block,
  517. + msblk->fragment[i].locked);
  518. + break;
  519. + }
  520. +
  521. + msblk->fragment[i].locked++;
  522. + up(&msblk->fragment_mutex);
  523. + TRACE("Got fragment %d, start block %lld, locked %d\n", i,
  524. + msblk->fragment[i].block,
  525. + msblk->fragment[i].locked);
  526. + break;
  527. + }
  528. +
  529. + return &msblk->fragment[i];
  530. +
  531. +out:
  532. + return NULL;
  533. +}
  534. +
  535. +
  536. +static struct inode *squashfs_new_inode(struct super_block *s,
  537. + struct squashfs_base_inode_header *inodeb)
  538. +{
  539. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  540. + struct inode *i = new_inode(s);
  541. +
  542. + if (i) {
  543. + i->i_ino = inodeb->inode_number;
  544. + i->i_mtime = inodeb->mtime;
  545. + i->i_atime = inodeb->mtime;
  546. + i->i_ctime = inodeb->mtime;
  547. + i->i_uid = msblk->uid[inodeb->uid];
  548. + i->i_mode = inodeb->mode;
  549. + i->i_size = 0;
  550. + if (inodeb->guid == SQUASHFS_GUIDS)
  551. + i->i_gid = i->i_uid;
  552. + else
  553. + i->i_gid = msblk->guid[inodeb->guid];
  554. + }
  555. +
  556. + return i;
  557. +}
  558. +
  559. +
  560. +static struct inode *squashfs_iget(struct super_block *s, squashfs_inode_t inode)
  561. +{
  562. + struct inode *i;
  563. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  564. + struct squashfs_super_block *sblk = &msblk->sblk;
  565. + long long block = SQUASHFS_INODE_BLK(inode) +
  566. + sblk->inode_table_start;
  567. + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
  568. + long long next_block;
  569. + unsigned int next_offset;
  570. + union squashfs_inode_header id, sid;
  571. + struct squashfs_base_inode_header *inodeb = &id.base,
  572. + *sinodeb = &sid.base;
  573. +
  574. + TRACE("Entered squashfs_iget\n");
  575. +
  576. + if (msblk->swap) {
  577. + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
  578. + offset, sizeof(*sinodeb), &next_block,
  579. + &next_offset))
  580. + goto failed_read;
  581. + SQUASHFS_SWAP_BASE_INODE_HEADER(inodeb, sinodeb,
  582. + sizeof(*sinodeb));
  583. + } else
  584. + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
  585. + offset, sizeof(*inodeb), &next_block,
  586. + &next_offset))
  587. + goto failed_read;
  588. +
  589. + switch(inodeb->inode_type) {
  590. + case SQUASHFS_FILE_TYPE: {
  591. + unsigned int frag_size;
  592. + long long frag_blk;
  593. + struct squashfs_reg_inode_header *inodep = &id.reg;
  594. + struct squashfs_reg_inode_header *sinodep = &sid.reg;
  595. +
  596. + if (msblk->swap) {
  597. + if (!squashfs_get_cached_block(s, (char *)
  598. + sinodep, block, offset,
  599. + sizeof(*sinodep), &next_block,
  600. + &next_offset))
  601. + goto failed_read;
  602. + SQUASHFS_SWAP_REG_INODE_HEADER(inodep, sinodep);
  603. + } else
  604. + if (!squashfs_get_cached_block(s, (char *)
  605. + inodep, block, offset,
  606. + sizeof(*inodep), &next_block,
  607. + &next_offset))
  608. + goto failed_read;
  609. +
  610. + frag_blk = SQUASHFS_INVALID_BLK;
  611. + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
  612. + !get_fragment_location(s,
  613. + inodep->fragment, &frag_blk, &frag_size))
  614. + goto failed_read;
  615. +
  616. + if((i = squashfs_new_inode(s, inodeb)) == NULL)
  617. + goto failed_read1;
  618. +
  619. + i->i_nlink = 1;
  620. + i->i_size = inodep->file_size;
  621. + i->i_fop = &generic_ro_fops;
  622. + i->i_mode |= S_IFREG;
  623. + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
  624. + i->i_blksize = PAGE_CACHE_SIZE;
  625. + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
  626. + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
  627. + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
  628. + SQUASHFS_I(i)->start_block = inodep->start_block;
  629. + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
  630. + SQUASHFS_I(i)->offset = next_offset;
  631. + if (sblk->block_size > 4096)
  632. + i->i_data.a_ops = &squashfs_aops;
  633. + else
  634. + i->i_data.a_ops = &squashfs_aops_4K;
  635. +
  636. + TRACE("File inode %x:%x, start_block %llx, "
  637. + "block_list_start %llx, offset %x\n",
  638. + SQUASHFS_INODE_BLK(inode), offset,
  639. + inodep->start_block, next_block,
  640. + next_offset);
  641. + break;
  642. + }
  643. + case SQUASHFS_LREG_TYPE: {
  644. + unsigned int frag_size;
  645. + long long frag_blk;
  646. + struct squashfs_lreg_inode_header *inodep = &id.lreg;
  647. + struct squashfs_lreg_inode_header *sinodep = &sid.lreg;
  648. +
  649. + if (msblk->swap) {
  650. + if (!squashfs_get_cached_block(s, (char *)
  651. + sinodep, block, offset,
  652. + sizeof(*sinodep), &next_block,
  653. + &next_offset))
  654. + goto failed_read;
  655. + SQUASHFS_SWAP_LREG_INODE_HEADER(inodep, sinodep);
  656. + } else
  657. + if (!squashfs_get_cached_block(s, (char *)
  658. + inodep, block, offset,
  659. + sizeof(*inodep), &next_block,
  660. + &next_offset))
  661. + goto failed_read;
  662. +
  663. + frag_blk = SQUASHFS_INVALID_BLK;
  664. + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
  665. + !get_fragment_location(s,
  666. + inodep->fragment, &frag_blk, &frag_size))
  667. + goto failed_read;
  668. +
  669. + if((i = squashfs_new_inode(s, inodeb)) == NULL)
  670. + goto failed_read1;
  671. +
  672. + i->i_nlink = inodep->nlink;
  673. + i->i_size = inodep->file_size;
  674. + i->i_fop = &generic_ro_fops;
  675. + i->i_mode |= S_IFREG;
  676. + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
  677. + i->i_blksize = PAGE_CACHE_SIZE;
  678. + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
  679. + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
  680. + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
  681. + SQUASHFS_I(i)->start_block = inodep->start_block;
  682. + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
  683. + SQUASHFS_I(i)->offset = next_offset;
  684. + if (sblk->block_size > 4096)
  685. + i->i_data.a_ops = &squashfs_aops;
  686. + else
  687. + i->i_data.a_ops = &squashfs_aops_4K;
  688. +
  689. + TRACE("File inode %x:%x, start_block %llx, "
  690. + "block_list_start %llx, offset %x\n",
  691. + SQUASHFS_INODE_BLK(inode), offset,
  692. + inodep->start_block, next_block,
  693. + next_offset);
  694. + break;
  695. + }
  696. + case SQUASHFS_DIR_TYPE: {
  697. + struct squashfs_dir_inode_header *inodep = &id.dir;
  698. + struct squashfs_dir_inode_header *sinodep = &sid.dir;
  699. +
  700. + if (msblk->swap) {
  701. + if (!squashfs_get_cached_block(s, (char *)
  702. + sinodep, block, offset,
  703. + sizeof(*sinodep), &next_block,
  704. + &next_offset))
  705. + goto failed_read;
  706. + SQUASHFS_SWAP_DIR_INODE_HEADER(inodep, sinodep);
  707. + } else
  708. + if (!squashfs_get_cached_block(s, (char *)
  709. + inodep, block, offset,
  710. + sizeof(*inodep), &next_block,
  711. + &next_offset))
  712. + goto failed_read;
  713. +
  714. + if((i = squashfs_new_inode(s, inodeb)) == NULL)
  715. + goto failed_read1;
  716. +
  717. + i->i_nlink = inodep->nlink;
  718. + i->i_size = inodep->file_size;
  719. + i->i_op = &squashfs_dir_inode_ops;
  720. + i->i_fop = &squashfs_dir_ops;
  721. + i->i_mode |= S_IFDIR;
  722. + SQUASHFS_I(i)->start_block = inodep->start_block;
  723. + SQUASHFS_I(i)->offset = inodep->offset;
  724. + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
  725. + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
  726. +
  727. + TRACE("Directory inode %x:%x, start_block %x, offset "
  728. + "%x\n", SQUASHFS_INODE_BLK(inode),
  729. + offset, inodep->start_block,
  730. + inodep->offset);
  731. + break;
  732. + }
  733. + case SQUASHFS_LDIR_TYPE: {
  734. + struct squashfs_ldir_inode_header *inodep = &id.ldir;
  735. + struct squashfs_ldir_inode_header *sinodep = &sid.ldir;
  736. +
  737. + if (msblk->swap) {
  738. + if (!squashfs_get_cached_block(s, (char *)
  739. + sinodep, block, offset,
  740. + sizeof(*sinodep), &next_block,
  741. + &next_offset))
  742. + goto failed_read;
  743. + SQUASHFS_SWAP_LDIR_INODE_HEADER(inodep,
  744. + sinodep);
  745. + } else
  746. + if (!squashfs_get_cached_block(s, (char *)
  747. + inodep, block, offset,
  748. + sizeof(*inodep), &next_block,
  749. + &next_offset))
  750. + goto failed_read;
  751. +
  752. + if((i = squashfs_new_inode(s, inodeb)) == NULL)
  753. + goto failed_read1;
  754. +
  755. + i->i_nlink = inodep->nlink;
  756. + i->i_size = inodep->file_size;
  757. + i->i_op = &squashfs_dir_inode_ops;
  758. + i->i_fop = &squashfs_dir_ops;
  759. + i->i_mode |= S_IFDIR;
  760. + SQUASHFS_I(i)->start_block = inodep->start_block;
  761. + SQUASHFS_I(i)->offset = inodep->offset;
  762. + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
  763. + SQUASHFS_I(i)->u.s2.directory_index_offset =
  764. + next_offset;
  765. + SQUASHFS_I(i)->u.s2.directory_index_count =
  766. + inodep->i_count;
  767. + SQUASHFS_I(i)->u.s2.parent_inode = inodep->parent_inode;
  768. +
  769. + TRACE("Long directory inode %x:%x, start_block %x, "
  770. + "offset %x\n",
  771. + SQUASHFS_INODE_BLK(inode), offset,
  772. + inodep->start_block, inodep->offset);
  773. + break;
  774. + }
  775. + case SQUASHFS_SYMLINK_TYPE: {
  776. + struct squashfs_symlink_inode_header *inodep =
  777. + &id.symlink;
  778. + struct squashfs_symlink_inode_header *sinodep =
  779. + &sid.symlink;
  780. +
  781. + if (msblk->swap) {
  782. + if (!squashfs_get_cached_block(s, (char *)
  783. + sinodep, block, offset,
  784. + sizeof(*sinodep), &next_block,
  785. + &next_offset))
  786. + goto failed_read;
  787. + SQUASHFS_SWAP_SYMLINK_INODE_HEADER(inodep,
  788. + sinodep);
  789. + } else
  790. + if (!squashfs_get_cached_block(s, (char *)
  791. + inodep, block, offset,
  792. + sizeof(*inodep), &next_block,
  793. + &next_offset))
  794. + goto failed_read;
  795. +
  796. + if((i = squashfs_new_inode(s, inodeb)) == NULL)
  797. + goto failed_read1;
  798. +
  799. + i->i_nlink = inodep->nlink;
  800. + i->i_size = inodep->symlink_size;
  801. + i->i_op = &page_symlink_inode_operations;
  802. + i->i_data.a_ops = &squashfs_symlink_aops;
  803. + i->i_mode |= S_IFLNK;
  804. + SQUASHFS_I(i)->start_block = next_block;
  805. + SQUASHFS_I(i)->offset = next_offset;
  806. +
  807. + TRACE("Symbolic link inode %x:%x, start_block %llx, "
  808. + "offset %x\n",
  809. + SQUASHFS_INODE_BLK(inode), offset,
  810. + next_block, next_offset);
  811. + break;
  812. + }
  813. + case SQUASHFS_BLKDEV_TYPE:
  814. + case SQUASHFS_CHRDEV_TYPE: {
  815. + struct squashfs_dev_inode_header *inodep = &id.dev;
  816. + struct squashfs_dev_inode_header *sinodep = &sid.dev;
  817. +
  818. + if (msblk->swap) {
  819. + if (!squashfs_get_cached_block(s, (char *)
  820. + sinodep, block, offset,
  821. + sizeof(*sinodep), &next_block,
  822. + &next_offset))
  823. + goto failed_read;
  824. + SQUASHFS_SWAP_DEV_INODE_HEADER(inodep, sinodep);
  825. + } else
  826. + if (!squashfs_get_cached_block(s, (char *)
  827. + inodep, block, offset,
  828. + sizeof(*inodep), &next_block,
  829. + &next_offset))
  830. + goto failed_read;
  831. +
  832. + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
  833. + goto failed_read1;
  834. +
  835. + i->i_nlink = inodep->nlink;
  836. + i->i_mode |= (inodeb->inode_type ==
  837. + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
  838. + S_IFBLK;
  839. + init_special_inode(i, i->i_mode, inodep->rdev);
  840. +
  841. + TRACE("Device inode %x:%x, rdev %x\n",
  842. + SQUASHFS_INODE_BLK(inode), offset,
  843. + inodep->rdev);
  844. + break;
  845. + }
  846. + case SQUASHFS_FIFO_TYPE:
  847. + case SQUASHFS_SOCKET_TYPE: {
  848. + struct squashfs_ipc_inode_header *inodep = &id.ipc;
  849. + struct squashfs_ipc_inode_header *sinodep = &sid.ipc;
  850. +
  851. + if (msblk->swap) {
  852. + if (!squashfs_get_cached_block(s, (char *)
  853. + sinodep, block, offset,
  854. + sizeof(*sinodep), &next_block,
  855. + &next_offset))
  856. + goto failed_read;
  857. + SQUASHFS_SWAP_IPC_INODE_HEADER(inodep, sinodep);
  858. + } else
  859. + if (!squashfs_get_cached_block(s, (char *)
  860. + inodep, block, offset,
  861. + sizeof(*inodep), &next_block,
  862. + &next_offset))
  863. + goto failed_read;
  864. +
  865. + if ((i = squashfs_new_inode(s, inodeb)) == NULL)
  866. + goto failed_read1;
  867. +
  868. + i->i_nlink = inodep->nlink;
  869. + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
  870. + ? S_IFIFO : S_IFSOCK;
  871. + init_special_inode(i, i->i_mode, 0);
  872. + break;
  873. + }
  874. + default:
  875. + ERROR("Unknown inode type %d in squashfs_iget!\n",
  876. + inodeb->inode_type);
  877. + goto failed_read1;
  878. + }
  879. +
  880. + insert_inode_hash(i);
  881. + return i;
  882. +
  883. +failed_read:
  884. + ERROR("Unable to read inode [%llx:%x]\n", block, offset);
  885. +
  886. +failed_read1:
  887. + return NULL;
  888. +}
  889. +
  890. +
  891. +int read_fragment_index_table(struct super_block *s)
  892. +{
  893. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  894. + struct squashfs_super_block *sblk = &msblk->sblk;
  895. +
  896. + if (!(msblk->fragment_index = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES
  897. + (sblk->fragments), GFP_KERNEL))) {
  898. + ERROR("Failed to allocate uid/gid table\n");
  899. + return 0;
  900. + }
  901. +
  902. + if (SQUASHFS_FRAGMENT_INDEX_BYTES(sblk->fragments) &&
  903. + !squashfs_read_data(s, (char *)
  904. + msblk->fragment_index,
  905. + sblk->fragment_table_start,
  906. + SQUASHFS_FRAGMENT_INDEX_BYTES
  907. + (sblk->fragments) |
  908. + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
  909. + ERROR("unable to read fragment index table\n");
  910. + return 0;
  911. + }
  912. +
  913. + if (msblk->swap) {
  914. + int i;
  915. + long long fragment;
  916. +
  917. + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES(sblk->fragments);
  918. + i++) {
  919. + SQUASHFS_SWAP_FRAGMENT_INDEXES((&fragment),
  920. + &msblk->fragment_index[i], 1);
  921. + msblk->fragment_index[i] = fragment;
  922. + }
  923. + }
  924. +
  925. + return 1;
  926. +}
  927. +
  928. +
  929. +static int supported_squashfs_filesystem(struct squashfs_sb_info *msblk, int silent)
  930. +{
  931. + struct squashfs_super_block *sblk = &msblk->sblk;
  932. +
  933. + msblk->iget = squashfs_iget;
  934. + msblk->read_blocklist = read_blocklist;
  935. + msblk->read_fragment_index_table = read_fragment_index_table;
  936. +
  937. + if (sblk->s_major == 1) {
  938. + if (!squashfs_1_0_supported(msblk)) {
  939. + SERROR("Major/Minor mismatch, Squashfs 1.0 filesystems "
  940. + "are unsupported\n");
  941. + SERROR("Please recompile with "
  942. + "Squashfs 1.0 support enabled\n");
  943. + return 0;
  944. + }
  945. + } else if (sblk->s_major == 2) {
  946. + if (!squashfs_2_0_supported(msblk)) {
  947. + SERROR("Major/Minor mismatch, Squashfs 2.0 filesystems "
  948. + "are unsupported\n");
  949. + SERROR("Please recompile with "
  950. + "Squashfs 2.0 support enabled\n");
  951. + return 0;
  952. + }
  953. + } else if(sblk->s_major != SQUASHFS_MAJOR || sblk->s_minor >
  954. + SQUASHFS_MINOR) {
  955. + SERROR("Major/Minor mismatch, trying to mount newer %d.%d "
  956. + "filesystem\n", sblk->s_major, sblk->s_minor);
  957. + SERROR("Please update your kernel\n");
  958. + return 0;
  959. + }
  960. +
  961. + return 1;
  962. +}
  963. +
  964. +
  965. +static struct super_block *squashfs_read_super(struct super_block *s,
  966. + void *data, int silent)
  967. +{
  968. + kdev_t dev = s->s_dev;
  969. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  970. + struct squashfs_super_block *sblk = &msblk->sblk;
  971. + int i;
  972. + struct inode *root;
  973. +
  974. + msblk->devblksize = get_hardsect_size(dev);
  975. + if(msblk->devblksize < BLOCK_SIZE)
  976. + msblk->devblksize = BLOCK_SIZE;
  977. + msblk->devblksize_log2 = ffz(~msblk->devblksize);
  978. + set_blocksize(dev, msblk->devblksize);
  979. + s->s_blocksize = msblk->devblksize;
  980. + s->s_blocksize_bits = msblk->devblksize_log2;
  981. +
  982. + init_MUTEX(&msblk->read_data_mutex);
  983. + init_MUTEX(&msblk->read_page_mutex);
  984. + init_MUTEX(&msblk->block_cache_mutex);
  985. + init_MUTEX(&msblk->fragment_mutex);
  986. +
  987. + init_waitqueue_head(&msblk->waitq);
  988. + init_waitqueue_head(&msblk->fragment_wait_queue);
  989. +
  990. + if (!squashfs_read_data(s, (char *) sblk, SQUASHFS_START,
  991. + sizeof(struct squashfs_super_block) |
  992. + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
  993. + SERROR("unable to read superblock\n");
  994. + goto failed_mount;
  995. + }
  996. +
  997. + /* Check it is a SQUASHFS superblock */
  998. + msblk->swap = 0;
  999. + if ((s->s_magic = sblk->s_magic) != SQUASHFS_MAGIC) {
  1000. + if (sblk->s_magic == SQUASHFS_MAGIC_SWAP) {
  1001. + struct squashfs_super_block ssblk;
  1002. +
  1003. + WARNING("Mounting a different endian SQUASHFS "
  1004. + "filesystem on %s\n", bdevname(dev));
  1005. +
  1006. + SQUASHFS_SWAP_SUPER_BLOCK(&ssblk, sblk);
  1007. + memcpy(sblk, &ssblk, sizeof(struct squashfs_super_block));
  1008. + msblk->swap = 1;
  1009. + } else {
  1010. + SERROR("Can't find a SQUASHFS superblock on %s\n",
  1011. + bdevname(dev));
  1012. + goto failed_mount;
  1013. + }
  1014. + }
  1015. +
  1016. + /* Check the MAJOR & MINOR versions */
  1017. + if(!supported_squashfs_filesystem(msblk, silent))
  1018. + goto failed_mount;
  1019. +
  1020. + TRACE("Found valid superblock on %s\n", bdevname(dev));
  1021. + TRACE("Inodes are %scompressed\n",
  1022. + SQUASHFS_UNCOMPRESSED_INODES
  1023. + (sblk->flags) ? "un" : "");
  1024. + TRACE("Data is %scompressed\n",
  1025. + SQUASHFS_UNCOMPRESSED_DATA(sblk->flags)
  1026. + ? "un" : "");
  1027. + TRACE("Check data is %s present in the filesystem\n",
  1028. + SQUASHFS_CHECK_DATA(sblk->flags) ?
  1029. + "" : "not");
  1030. + TRACE("Filesystem size %lld bytes\n", sblk->bytes_used);
  1031. + TRACE("Block size %d\n", sblk->block_size);
  1032. + TRACE("Number of inodes %d\n", sblk->inodes);
  1033. + if (sblk->s_major > 1)
  1034. + TRACE("Number of fragments %d\n", sblk->fragments);
  1035. + TRACE("Number of uids %d\n", sblk->no_uids);
  1036. + TRACE("Number of gids %d\n", sblk->no_guids);
  1037. + TRACE("sblk->inode_table_start %llx\n", sblk->inode_table_start);
  1038. + TRACE("sblk->directory_table_start %llx\n", sblk->directory_table_start);
  1039. + if (sblk->s_major > 1)
  1040. + TRACE("sblk->fragment_table_start %llx\n",
  1041. + sblk->fragment_table_start);
  1042. + TRACE("sblk->uid_start %llx\n", sblk->uid_start);
  1043. +
  1044. + s->s_flags |= MS_RDONLY;
  1045. + s->s_op = &squashfs_ops;
  1046. +
  1047. + /* Init inode_table block pointer array */
  1048. + if (!(msblk->block_cache = kmalloc(sizeof(struct squashfs_cache) *
  1049. + SQUASHFS_CACHED_BLKS, GFP_KERNEL))) {
  1050. + ERROR("Failed to allocate block cache\n");
  1051. + goto failed_mount;
  1052. + }
  1053. +
  1054. + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
  1055. + msblk->block_cache[i].block = SQUASHFS_INVALID_BLK;
  1056. +
  1057. + msblk->next_cache = 0;
  1058. +
  1059. + /* Allocate read_data block */
  1060. + msblk->read_size = (sblk->block_size < SQUASHFS_METADATA_SIZE) ?
  1061. + SQUASHFS_METADATA_SIZE :
  1062. + sblk->block_size;
  1063. +
  1064. + if (!(msblk->read_data = kmalloc(msblk->read_size, GFP_KERNEL))) {
  1065. + ERROR("Failed to allocate read_data block\n");
  1066. + goto failed_mount;
  1067. + }
  1068. +
  1069. + /* Allocate read_page block */
  1070. + if (!(msblk->read_page = kmalloc(sblk->block_size, GFP_KERNEL))) {
  1071. + ERROR("Failed to allocate read_page block\n");
  1072. + goto failed_mount;
  1073. + }
  1074. +
  1075. + /* Allocate uid and gid tables */
  1076. + if (!(msblk->uid = kmalloc((sblk->no_uids + sblk->no_guids) *
  1077. + sizeof(unsigned int), GFP_KERNEL))) {
  1078. + ERROR("Failed to allocate uid/gid table\n");
  1079. + goto failed_mount;
  1080. + }
  1081. + msblk->guid = msblk->uid + sblk->no_uids;
  1082. +
  1083. + if (msblk->swap) {
  1084. + unsigned int suid[sblk->no_uids + sblk->no_guids];
  1085. +
  1086. + if (!squashfs_read_data(s, (char *) &suid, sblk->uid_start,
  1087. + ((sblk->no_uids + sblk->no_guids) *
  1088. + sizeof(unsigned int)) |
  1089. + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
  1090. + ERROR("unable to read uid/gid table\n");
  1091. + goto failed_mount;
  1092. + }
  1093. +
  1094. + SQUASHFS_SWAP_DATA(msblk->uid, suid, (sblk->no_uids +
  1095. + sblk->no_guids), (sizeof(unsigned int) * 8));
  1096. + } else
  1097. + if (!squashfs_read_data(s, (char *) msblk->uid, sblk->uid_start,
  1098. + ((sblk->no_uids + sblk->no_guids) *
  1099. + sizeof(unsigned int)) |
  1100. + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
  1101. + ERROR("unable to read uid/gid table\n");
  1102. + goto failed_mount;
  1103. + }
  1104. +
  1105. +
  1106. + if (sblk->s_major == 1 && squashfs_1_0_supported(msblk))
  1107. + goto allocate_root;
  1108. +
  1109. + if (!(msblk->fragment = kmalloc(sizeof(struct squashfs_fragment_cache) *
  1110. + SQUASHFS_CACHED_FRAGMENTS, GFP_KERNEL))) {
  1111. + ERROR("Failed to allocate fragment block cache\n");
  1112. + goto failed_mount;
  1113. + }
  1114. +
  1115. + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++) {
  1116. + msblk->fragment[i].locked = 0;
  1117. + msblk->fragment[i].block = SQUASHFS_INVALID_BLK;
  1118. + msblk->fragment[i].data = NULL;
  1119. + }
  1120. +
  1121. + msblk->next_fragment = 0;
  1122. +
  1123. + /* Allocate fragment index table */
  1124. + if(msblk->read_fragment_index_table(s) == 0)
  1125. + goto failed_mount;
  1126. +
  1127. +allocate_root:
  1128. + if ((root = (msblk->iget)(s, sblk->root_inode)) == NULL)
  1129. + goto failed_mount;
  1130. +
  1131. + if ((s->s_root = d_alloc_root(root)) == NULL) {
  1132. + ERROR("Root inode create failed\n");
  1133. + iput(root);
  1134. + goto failed_mount;
  1135. + }
  1136. +
  1137. + TRACE("Leaving squashfs_read_super\n");
  1138. + return s;
  1139. +
  1140. +failed_mount:
  1141. + kfree(msblk->fragment_index);
  1142. + kfree(msblk->fragment);
  1143. + kfree(msblk->uid);
  1144. + kfree(msblk->read_page);
  1145. + kfree(msblk->read_data);
  1146. + kfree(msblk->block_cache);
  1147. + kfree(msblk->fragment_index_2);
  1148. + return NULL;
  1149. +}
  1150. +
  1151. +
  1152. +static int squashfs_statfs(struct super_block *s, struct statfs *buf)
  1153. +{
  1154. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  1155. + struct squashfs_super_block *sblk = &msblk->sblk;
  1156. +
  1157. + TRACE("Entered squashfs_statfs\n");
  1158. +
  1159. + buf->f_type = SQUASHFS_MAGIC;
  1160. + buf->f_bsize = sblk->block_size;
  1161. + buf->f_blocks = ((sblk->bytes_used - 1) >> sblk->block_log) + 1;
  1162. + buf->f_bfree = buf->f_bavail = 0;
  1163. + buf->f_files = sblk->inodes;
  1164. + buf->f_ffree = 0;
  1165. + buf->f_namelen = SQUASHFS_NAME_LEN;
  1166. +
  1167. + return 0;
  1168. +}
  1169. +
  1170. +
  1171. +static int squashfs_symlink_readpage(struct file *file, struct page *page)
  1172. +{
  1173. + struct inode *inode = page->mapping->host;
  1174. + int index = page->index << PAGE_CACHE_SHIFT, length, bytes;
  1175. + long long block = SQUASHFS_I(inode)->start_block;
  1176. + int offset = SQUASHFS_I(inode)->offset;
  1177. + void *pageaddr = kmap(page);
  1178. +
  1179. + TRACE("Entered squashfs_symlink_readpage, page index %ld, start block "
  1180. + "%llx, offset %x\n", page->index,
  1181. + SQUASHFS_I(inode)->start_block,
  1182. + SQUASHFS_I(inode)->offset);
  1183. +
  1184. + for (length = 0; length < index; length += bytes) {
  1185. + if (!(bytes = squashfs_get_cached_block(inode->i_sb, NULL,
  1186. + block, offset, PAGE_CACHE_SIZE, &block,
  1187. + &offset))) {
  1188. + ERROR("Unable to read symbolic link [%llx:%x]\n", block,
  1189. + offset);
  1190. + goto skip_read;
  1191. + }
  1192. + }
  1193. +
  1194. + if (length != index) {
  1195. + ERROR("(squashfs_symlink_readpage) length != index\n");
  1196. + bytes = 0;
  1197. + goto skip_read;
  1198. + }
  1199. +
  1200. + bytes = (i_size_read(inode) - length) > PAGE_CACHE_SIZE ? PAGE_CACHE_SIZE :
  1201. + i_size_read(inode) - length;
  1202. +
  1203. + if (!(bytes = squashfs_get_cached_block(inode->i_sb, pageaddr, block,
  1204. + offset, bytes, &block, &offset)))
  1205. + ERROR("Unable to read symbolic link [%llx:%x]\n", block, offset);
  1206. +
  1207. +skip_read:
  1208. + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
  1209. + kunmap(page);
  1210. + SetPageUptodate(page);
  1211. + UnlockPage(page);
  1212. +
  1213. + return 0;
  1214. +}
  1215. +
  1216. +
  1217. +struct meta_index *locate_meta_index(struct inode *inode, int index, int offset)
  1218. +{
  1219. + struct meta_index *meta = NULL;
  1220. + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
  1221. + int i;
  1222. +
  1223. + down(&msblk->meta_index_mutex);
  1224. +
  1225. + TRACE("locate_meta_index: index %d, offset %d\n", index, offset);
  1226. +
  1227. + if(msblk->meta_index == NULL)
  1228. + goto not_allocated;
  1229. +
  1230. + for (i = 0; i < SQUASHFS_META_NUMBER; i ++)
  1231. + if (msblk->meta_index[i].inode_number == inode->i_ino &&
  1232. + msblk->meta_index[i].offset >= offset &&
  1233. + msblk->meta_index[i].offset <= index &&
  1234. + msblk->meta_index[i].locked == 0) {
  1235. + TRACE("locate_meta_index: entry %d, offset %d\n", i,
  1236. + msblk->meta_index[i].offset);
  1237. + meta = &msblk->meta_index[i];
  1238. + offset = meta->offset;
  1239. + }
  1240. +
  1241. + if (meta)
  1242. + meta->locked = 1;
  1243. +
  1244. +not_allocated:
  1245. + up(&msblk->meta_index_mutex);
  1246. +
  1247. + return meta;
  1248. +}
  1249. +
  1250. +
  1251. +struct meta_index *empty_meta_index(struct inode *inode, int offset, int skip)
  1252. +{
  1253. + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
  1254. + struct meta_index *meta = NULL;
  1255. + int i;
  1256. +
  1257. + down(&msblk->meta_index_mutex);
  1258. +
  1259. + TRACE("empty_meta_index: offset %d, skip %d\n", offset, skip);
  1260. +
  1261. + if(msblk->meta_index == NULL) {
  1262. + if (!(msblk->meta_index = kmalloc(sizeof(struct meta_index) *
  1263. + SQUASHFS_META_NUMBER, GFP_KERNEL))) {
  1264. + ERROR("Failed to allocate meta_index\n");
  1265. + goto failed;
  1266. + }
  1267. + for(i = 0; i < SQUASHFS_META_NUMBER; i++) {
  1268. + msblk->meta_index[i].inode_number = 0;
  1269. + msblk->meta_index[i].locked = 0;
  1270. + }
  1271. + msblk->next_meta_index = 0;
  1272. + }
  1273. +
  1274. + for(i = SQUASHFS_META_NUMBER; i &&
  1275. + msblk->meta_index[msblk->next_meta_index].locked; i --)
  1276. + msblk->next_meta_index = (msblk->next_meta_index + 1) %
  1277. + SQUASHFS_META_NUMBER;
  1278. +
  1279. + if(i == 0) {
  1280. + TRACE("empty_meta_index: failed!\n");
  1281. + goto failed;
  1282. + }
  1283. +
  1284. + TRACE("empty_meta_index: returned meta entry %d, %p\n",
  1285. + msblk->next_meta_index,
  1286. + &msblk->meta_index[msblk->next_meta_index]);
  1287. +
  1288. + meta = &msblk->meta_index[msblk->next_meta_index];
  1289. + msblk->next_meta_index = (msblk->next_meta_index + 1) %
  1290. + SQUASHFS_META_NUMBER;
  1291. +
  1292. + meta->inode_number = inode->i_ino;
  1293. + meta->offset = offset;
  1294. + meta->skip = skip;
  1295. + meta->entries = 0;
  1296. + meta->locked = 1;
  1297. +
  1298. +failed:
  1299. + up(&msblk->meta_index_mutex);
  1300. + return meta;
  1301. +}
  1302. +
  1303. +
  1304. +void release_meta_index(struct inode *inode, struct meta_index *meta)
  1305. +{
  1306. + meta->locked = 0;
  1307. +}
  1308. +
  1309. +
  1310. +static int read_block_index(struct super_block *s, int blocks, char *block_list,
  1311. + long long *start_block, int *offset)
  1312. +{
  1313. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  1314. + unsigned int *block_listp;
  1315. + int block = 0;
  1316. +
  1317. + if (msblk->swap) {
  1318. + char sblock_list[blocks << 2];
  1319. +
  1320. + if (!squashfs_get_cached_block(s, sblock_list, *start_block,
  1321. + *offset, blocks << 2, start_block, offset)) {
  1322. + ERROR("Unable to read block list [%llx:%x]\n",
  1323. + *start_block, *offset);
  1324. + goto failure;
  1325. + }
  1326. + SQUASHFS_SWAP_INTS(((unsigned int *)block_list),
  1327. + ((unsigned int *)sblock_list), blocks);
  1328. + } else
  1329. + if (!squashfs_get_cached_block(s, block_list, *start_block,
  1330. + *offset, blocks << 2, start_block, offset)) {
  1331. + ERROR("Unable to read block list [%llx:%x]\n",
  1332. + *start_block, *offset);
  1333. + goto failure;
  1334. + }
  1335. +
  1336. + for (block_listp = (unsigned int *) block_list; blocks;
  1337. + block_listp++, blocks --)
  1338. + block += SQUASHFS_COMPRESSED_SIZE_BLOCK(*block_listp);
  1339. +
  1340. + return block;
  1341. +
  1342. +failure:
  1343. + return -1;
  1344. +}
  1345. +
  1346. +
  1347. +#define SIZE 256
  1348. +
  1349. +static inline int calculate_skip(int blocks) {
  1350. + int skip = (blocks - 1) / ((SQUASHFS_SLOTS * SQUASHFS_META_ENTRIES + 1) * SQUASHFS_META_INDEXES);
  1351. + return skip >= 7 ? 7 : skip + 1;
  1352. +}
  1353. +
  1354. +
  1355. +static int get_meta_index(struct inode *inode, int index,
  1356. + long long *index_block, int *index_offset,
  1357. + long long *data_block, char *block_list)
  1358. +{
  1359. + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
  1360. + struct squashfs_super_block *sblk = &msblk->sblk;
  1361. + int skip = calculate_skip(i_size_read(inode) >> sblk->block_log);
  1362. + int offset = 0;
  1363. + struct meta_index *meta;
  1364. + struct meta_entry *meta_entry;
  1365. + long long cur_index_block = SQUASHFS_I(inode)->u.s1.block_list_start;
  1366. + int cur_offset = SQUASHFS_I(inode)->offset;
  1367. + long long cur_data_block = SQUASHFS_I(inode)->start_block;
  1368. + int i;
  1369. +
  1370. + index /= SQUASHFS_META_INDEXES * skip;
  1371. +
  1372. + while ( offset < index ) {
  1373. + meta = locate_meta_index(inode, index, offset + 1);
  1374. +
  1375. + if (meta == NULL) {
  1376. + if ((meta = empty_meta_index(inode, offset + 1,
  1377. + skip)) == NULL)
  1378. + goto all_done;
  1379. + } else {
  1380. + offset = index < meta->offset + meta->entries ? index :
  1381. + meta->offset + meta->entries - 1;
  1382. + meta_entry = &meta->meta_entry[offset - meta->offset];
  1383. + cur_index_block = meta_entry->index_block + sblk->inode_table_start;
  1384. + cur_offset = meta_entry->offset;
  1385. + cur_data_block = meta_entry->data_block;
  1386. + TRACE("get_meta_index: offset %d, meta->offset %d, "
  1387. + "meta->entries %d\n", offset, meta->offset,
  1388. + meta->entries);
  1389. + TRACE("get_meta_index: index_block 0x%llx, offset 0x%x"
  1390. + " data_block 0x%llx\n", cur_index_block,
  1391. + cur_offset, cur_data_block);
  1392. + }
  1393. +
  1394. + for (i = meta->offset + meta->entries; i <= index &&
  1395. + i < meta->offset + SQUASHFS_META_ENTRIES; i++) {
  1396. + int blocks = skip * SQUASHFS_META_INDEXES;
  1397. +
  1398. + while (blocks) {
  1399. + int block = blocks > (SIZE >> 2) ? (SIZE >> 2) :
  1400. + blocks;
  1401. + int res = read_block_index(inode->i_sb, block,
  1402. + block_list, &cur_index_block,
  1403. + &cur_offset);
  1404. +
  1405. + if (res == -1)
  1406. + goto failed;
  1407. +
  1408. + cur_data_block += res;
  1409. + blocks -= block;
  1410. + }
  1411. +
  1412. + meta_entry = &meta->meta_entry[i - meta->offset];
  1413. + meta_entry->index_block = cur_index_block - sblk->inode_table_start;
  1414. + meta_entry->offset = cur_offset;
  1415. + meta_entry->data_block = cur_data_block;
  1416. + meta->entries ++;
  1417. + offset ++;
  1418. + }
  1419. +
  1420. + TRACE("get_meta_index: meta->offset %d, meta->entries %d\n",
  1421. + meta->offset, meta->entries);
  1422. +
  1423. + release_meta_index(inode, meta);
  1424. + }
  1425. +
  1426. +all_done:
  1427. + *index_block = cur_index_block;
  1428. + *index_offset = cur_offset;
  1429. + *data_block = cur_data_block;
  1430. +
  1431. + return offset * SQUASHFS_META_INDEXES * skip;
  1432. +
  1433. +failed:
  1434. + release_meta_index(inode, meta);
  1435. + return -1;
  1436. +}
  1437. +
  1438. +
  1439. +static long long read_blocklist(struct inode *inode, int index,
  1440. + int readahead_blks, char *block_list,
  1441. + unsigned short **block_p, unsigned int *bsize)
  1442. +{
  1443. + long long block_ptr;
  1444. + int offset;
  1445. + long long block;
  1446. + int res = get_meta_index(inode, index, &block_ptr, &offset, &block,
  1447. + block_list);
  1448. +
  1449. + TRACE("read_blocklist: res %d, index %d, block_ptr 0x%llx, offset"
  1450. + " 0x%x, block 0x%llx\n", res, index, block_ptr, offset,
  1451. + block);
  1452. +
  1453. + if(res == -1)
  1454. + goto failure;
  1455. +
  1456. + index -= res;
  1457. +
  1458. + while ( index ) {
  1459. + int blocks = index > (SIZE >> 2) ? (SIZE >> 2) : index;
  1460. + int res = read_block_index(inode->i_sb, blocks, block_list,
  1461. + &block_ptr, &offset);
  1462. + if (res == -1)
  1463. + goto failure;
  1464. + block += res;
  1465. + index -= blocks;
  1466. + }
  1467. +
  1468. + if (read_block_index(inode->i_sb, 1, block_list,
  1469. + &block_ptr, &offset) == -1)
  1470. + goto failure;
  1471. + *bsize = *((unsigned int *) block_list);
  1472. +
  1473. + return block;
  1474. +
  1475. +failure:
  1476. + return 0;
  1477. +}
  1478. +
  1479. +
  1480. +static int squashfs_readpage(struct file *file, struct page *page)
  1481. +{
  1482. + struct inode *inode = page->mapping->host;
  1483. + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
  1484. + struct squashfs_super_block *sblk = &msblk->sblk;
  1485. + unsigned char block_list[SIZE];
  1486. + long long block;
  1487. + unsigned int bsize, i = 0, bytes = 0, byte_offset = 0;
  1488. + int index = page->index >> (sblk->block_log - PAGE_CACHE_SHIFT);
  1489. + void *pageaddr;
  1490. + struct squashfs_fragment_cache *fragment = NULL;
  1491. + char *data_ptr = msblk->read_page;
  1492. +
  1493. + int mask = (1 << (sblk->block_log - PAGE_CACHE_SHIFT)) - 1;
  1494. + int start_index = page->index & ~mask;
  1495. + int end_index = start_index | mask;
  1496. +
  1497. + TRACE("Entered squashfs_readpage, page index %lx, start block %llx\n",
  1498. + page->index,
  1499. + SQUASHFS_I(inode)->start_block);
  1500. +
  1501. + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
  1502. + PAGE_CACHE_SHIFT))
  1503. + goto skip_read;
  1504. +
  1505. + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
  1506. + || index < (i_size_read(inode) >>
  1507. + sblk->block_log)) {
  1508. + if ((block = (msblk->read_blocklist)(inode, index, 1,
  1509. + block_list, NULL, &bsize)) == 0)
  1510. + goto skip_read;
  1511. +
  1512. + down(&msblk->read_page_mutex);
  1513. +
  1514. + if (!(bytes = squashfs_read_data(inode->i_sb, msblk->read_page,
  1515. + block, bsize, NULL))) {
  1516. + ERROR("Unable to read page, block %llx, size %x\n", block,
  1517. + bsize);
  1518. + up(&msblk->read_page_mutex);
  1519. + goto skip_read;
  1520. + }
  1521. + } else {
  1522. + if ((fragment = get_cached_fragment(inode->i_sb,
  1523. + SQUASHFS_I(inode)->
  1524. + u.s1.fragment_start_block,
  1525. + SQUASHFS_I(inode)->u.s1.fragment_size))
  1526. + == NULL) {
  1527. + ERROR("Unable to read page, block %llx, size %x\n",
  1528. + SQUASHFS_I(inode)->
  1529. + u.s1.fragment_start_block,
  1530. + (int) SQUASHFS_I(inode)->
  1531. + u.s1.fragment_size);
  1532. + goto skip_read;
  1533. + }
  1534. + bytes = SQUASHFS_I(inode)->u.s1.fragment_offset +
  1535. + (i_size_read(inode) & (sblk->block_size
  1536. + - 1));
  1537. + byte_offset = SQUASHFS_I(inode)->u.s1.fragment_offset;
  1538. + data_ptr = fragment->data;
  1539. + }
  1540. +
  1541. + for (i = start_index; i <= end_index && byte_offset < bytes;
  1542. + i++, byte_offset += PAGE_CACHE_SIZE) {
  1543. + struct page *push_page;
  1544. + int available_bytes = (bytes - byte_offset) > PAGE_CACHE_SIZE ?
  1545. + PAGE_CACHE_SIZE : bytes - byte_offset;
  1546. +
  1547. + TRACE("bytes %d, i %d, byte_offset %d, available_bytes %d\n",
  1548. + bytes, i, byte_offset, available_bytes);
  1549. +
  1550. + if (i == page->index) {
  1551. + pageaddr = kmap_atomic(page, KM_USER0);
  1552. + memcpy(pageaddr, data_ptr + byte_offset,
  1553. + available_bytes);
  1554. + memset(pageaddr + available_bytes, 0,
  1555. + PAGE_CACHE_SIZE - available_bytes);
  1556. + kunmap_atomic(pageaddr, KM_USER0);
  1557. + flush_dcache_page(page);
  1558. + SetPageUptodate(page);
  1559. + UnlockPage(page);
  1560. + } else if ((push_page =
  1561. + grab_cache_page_nowait(page->mapping, i))) {
  1562. + pageaddr = kmap_atomic(push_page, KM_USER0);
  1563. +
  1564. + memcpy(pageaddr, data_ptr + byte_offset,
  1565. + available_bytes);
  1566. + memset(pageaddr + available_bytes, 0,
  1567. + PAGE_CACHE_SIZE - available_bytes);
  1568. + kunmap_atomic(pageaddr, KM_USER0);
  1569. + flush_dcache_page(push_page);
  1570. + SetPageUptodate(push_page);
  1571. + UnlockPage(push_page);
  1572. + page_cache_release(push_page);
  1573. + }
  1574. + }
  1575. +
  1576. + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
  1577. + || index < (i_size_read(inode) >>
  1578. + sblk->block_log))
  1579. + up(&msblk->read_page_mutex);
  1580. + else
  1581. + release_cached_fragment(msblk, fragment);
  1582. +
  1583. + return 0;
  1584. +
  1585. +skip_read:
  1586. + pageaddr = kmap_atomic(page, KM_USER0);
  1587. + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
  1588. + kunmap_atomic(pageaddr, KM_USER0);
  1589. + flush_dcache_page(page);
  1590. + SetPageUptodate(page);
  1591. + UnlockPage(page);
  1592. +
  1593. + return 0;
  1594. +}
  1595. +
  1596. +
  1597. +static int squashfs_readpage4K(struct file *file, struct page *page)
  1598. +{
  1599. + struct inode *inode = page->mapping->host;
  1600. + struct squashfs_sb_info *msblk = &inode->i_sb->u.squashfs_sb;
  1601. + struct squashfs_super_block *sblk = &msblk->sblk;
  1602. + unsigned char block_list[SIZE];
  1603. + long long block;
  1604. + unsigned int bsize, bytes = 0;
  1605. + void *pageaddr;
  1606. +
  1607. + TRACE("Entered squashfs_readpage4K, page index %lx, start block %llx\n",
  1608. + page->index,
  1609. + SQUASHFS_I(inode)->start_block);
  1610. +
  1611. + if (page->index >= ((i_size_read(inode) + PAGE_CACHE_SIZE - 1) >>
  1612. + PAGE_CACHE_SHIFT)) {
  1613. + pageaddr = kmap_atomic(page, KM_USER0);
  1614. + goto skip_read;
  1615. + }
  1616. +
  1617. + if (SQUASHFS_I(inode)->u.s1.fragment_start_block == SQUASHFS_INVALID_BLK
  1618. + || page->index < (i_size_read(inode) >>
  1619. + sblk->block_log)) {
  1620. + block = (msblk->read_blocklist)(inode, page->index, 1,
  1621. + block_list, NULL, &bsize);
  1622. +
  1623. + down(&msblk->read_page_mutex);
  1624. + bytes = squashfs_read_data(inode->i_sb, msblk->read_page, block,
  1625. + bsize, NULL);
  1626. + pageaddr = kmap_atomic(page, KM_USER0);
  1627. + if (bytes)
  1628. + memcpy(pageaddr, msblk->read_page, bytes);
  1629. + else
  1630. + ERROR("Unable to read page, block %llx, size %x\n",
  1631. + block, bsize);
  1632. + up(&msblk->read_page_mutex);
  1633. + } else {
  1634. + struct squashfs_fragment_cache *fragment =
  1635. + get_cached_fragment(inode->i_sb,
  1636. + SQUASHFS_I(inode)->
  1637. + u.s1.fragment_start_block,
  1638. + SQUASHFS_I(inode)-> u.s1.fragment_size);
  1639. + pageaddr = kmap_atomic(page, KM_USER0);
  1640. + if (fragment) {
  1641. + bytes = i_size_read(inode) & (sblk->block_size - 1);
  1642. + memcpy(pageaddr, fragment->data + SQUASHFS_I(inode)->
  1643. + u.s1.fragment_offset, bytes);
  1644. + release_cached_fragment(msblk, fragment);
  1645. + } else
  1646. + ERROR("Unable to read page, block %llx, size %x\n",
  1647. + SQUASHFS_I(inode)->
  1648. + u.s1.fragment_start_block, (int)
  1649. + SQUASHFS_I(inode)-> u.s1.fragment_size);
  1650. + }
  1651. +
  1652. +skip_read:
  1653. + memset(pageaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
  1654. + kunmap_atomic(pageaddr, KM_USER0);
  1655. + flush_dcache_page(page);
  1656. + SetPageUptodate(page);
  1657. + UnlockPage(page);
  1658. +
  1659. + return 0;
  1660. +}
  1661. +
  1662. +
  1663. +static int get_dir_index_using_offset(struct super_block *s, long long
  1664. + *next_block, unsigned int *next_offset,
  1665. + long long index_start,
  1666. + unsigned int index_offset, int i_count,
  1667. + long long f_pos)
  1668. +{
  1669. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  1670. + struct squashfs_super_block *sblk = &msblk->sblk;
  1671. + int i, length = 0;
  1672. + struct squashfs_dir_index index;
  1673. +
  1674. + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
  1675. + i_count, (unsigned int) f_pos);
  1676. +
  1677. + f_pos -= 3;
  1678. + if (f_pos == 0)
  1679. + goto finish;
  1680. +
  1681. + for (i = 0; i < i_count; i++) {
  1682. + if (msblk->swap) {
  1683. + struct squashfs_dir_index sindex;
  1684. + squashfs_get_cached_block(s, (char *) &sindex,
  1685. + index_start, index_offset,
  1686. + sizeof(sindex), &index_start,
  1687. + &index_offset);
  1688. + SQUASHFS_SWAP_DIR_INDEX(&index, &sindex);
  1689. + } else
  1690. + squashfs_get_cached_block(s, (char *) &index,
  1691. + index_start, index_offset,
  1692. + sizeof(index), &index_start,
  1693. + &index_offset);
  1694. +
  1695. + if (index.index > f_pos)
  1696. + break;
  1697. +
  1698. + squashfs_get_cached_block(s, NULL, index_start, index_offset,
  1699. + index.size + 1, &index_start,
  1700. + &index_offset);
  1701. +
  1702. + length = index.index;
  1703. + *next_block = index.start_block + sblk->directory_table_start;
  1704. + }
  1705. +
  1706. + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
  1707. +
  1708. +finish:
  1709. + return length + 3;
  1710. +}
  1711. +
  1712. +
  1713. +static int get_dir_index_using_name(struct super_block *s, long long
  1714. + *next_block, unsigned int *next_offset,
  1715. + long long index_start,
  1716. + unsigned int index_offset, int i_count,
  1717. + const char *name, int size)
  1718. +{
  1719. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  1720. + struct squashfs_super_block *sblk = &msblk->sblk;
  1721. + int i, length = 0;
  1722. + char buffer[sizeof(struct squashfs_dir_index) + SQUASHFS_NAME_LEN + 1];
  1723. + struct squashfs_dir_index *index = (struct squashfs_dir_index *) buffer;
  1724. + char str[SQUASHFS_NAME_LEN + 1];
  1725. +
  1726. + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
  1727. +
  1728. + strncpy(str, name, size);
  1729. + str[size] = '\0';
  1730. +
  1731. + for (i = 0; i < i_count; i++) {
  1732. + if (msblk->swap) {
  1733. + struct squashfs_dir_index sindex;
  1734. + squashfs_get_cached_block(s, (char *) &sindex,
  1735. + index_start, index_offset,
  1736. + sizeof(sindex), &index_start,
  1737. + &index_offset);
  1738. + SQUASHFS_SWAP_DIR_INDEX(index, &sindex);
  1739. + } else
  1740. + squashfs_get_cached_block(s, (char *) index,
  1741. + index_start, index_offset,
  1742. + sizeof(struct squashfs_dir_index),
  1743. + &index_start, &index_offset);
  1744. +
  1745. + squashfs_get_cached_block(s, index->name, index_start,
  1746. + index_offset, index->size + 1,
  1747. + &index_start, &index_offset);
  1748. +
  1749. + index->name[index->size + 1] = '\0';
  1750. +
  1751. + if (strcmp(index->name, str) > 0)
  1752. + break;
  1753. +
  1754. + length = index->index;
  1755. + *next_block = index->start_block + sblk->directory_table_start;
  1756. + }
  1757. +
  1758. + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
  1759. + return length + 3;
  1760. +}
  1761. +
  1762. +
  1763. +static int squashfs_readdir(struct file *file, void *dirent, filldir_t filldir)
  1764. +{
  1765. + struct inode *i = file->f_dentry->d_inode;
  1766. + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
  1767. + struct squashfs_super_block *sblk = &msblk->sblk;
  1768. + long long next_block = SQUASHFS_I(i)->start_block +
  1769. + sblk->directory_table_start;
  1770. + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
  1771. + dir_count;
  1772. + struct squashfs_dir_header dirh;
  1773. + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN + 1];
  1774. + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
  1775. +
  1776. + TRACE("Entered squashfs_readdir [%llx:%x]\n", next_block, next_offset);
  1777. +
  1778. + while(file->f_pos < 3) {
  1779. + char *name;
  1780. + int size, i_ino;
  1781. +
  1782. + if(file->f_pos == 0) {
  1783. + name = ".";
  1784. + size = 1;
  1785. + i_ino = i->i_ino;
  1786. + } else {
  1787. + name = "..";
  1788. + size = 2;
  1789. + i_ino = SQUASHFS_I(i)->u.s2.parent_inode;
  1790. + }
  1791. + TRACE("Calling filldir(%x, %s, %d, %d, %d, %d)\n",
  1792. + (unsigned int) dirent, name, size, (int)
  1793. + file->f_pos, i_ino,
  1794. + squashfs_filetype_table[1]);
  1795. +
  1796. + if (filldir(dirent, name, size,
  1797. + file->f_pos, i_ino,
  1798. + squashfs_filetype_table[1]) < 0) {
  1799. + TRACE("Filldir returned less than 0\n");
  1800. + goto finish;
  1801. + }
  1802. + file->f_pos += size;
  1803. + dirs_read++;
  1804. + }
  1805. +
  1806. + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
  1807. + SQUASHFS_I(i)->u.s2.directory_index_start,
  1808. + SQUASHFS_I(i)->u.s2.directory_index_offset,
  1809. + SQUASHFS_I(i)->u.s2.directory_index_count,
  1810. + file->f_pos);
  1811. +
  1812. + while (length < i_size_read(i)) {
  1813. + /* read directory header */
  1814. + if (msblk->swap) {
  1815. + struct squashfs_dir_header sdirh;
  1816. +
  1817. + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
  1818. + next_block, next_offset, sizeof(sdirh),
  1819. + &next_block, &next_offset))
  1820. + goto failed_read;
  1821. +
  1822. + length += sizeof(sdirh);
  1823. + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
  1824. + } else {
  1825. + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
  1826. + next_block, next_offset, sizeof(dirh),
  1827. + &next_block, &next_offset))
  1828. + goto failed_read;
  1829. +
  1830. + length += sizeof(dirh);
  1831. + }
  1832. +
  1833. + dir_count = dirh.count + 1;
  1834. + while (dir_count--) {
  1835. + if (msblk->swap) {
  1836. + struct squashfs_dir_entry sdire;
  1837. + if (!squashfs_get_cached_block(i->i_sb, (char *)
  1838. + &sdire, next_block, next_offset,
  1839. + sizeof(sdire), &next_block,
  1840. + &next_offset))
  1841. + goto failed_read;
  1842. +
  1843. + length += sizeof(sdire);
  1844. + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
  1845. + } else {
  1846. + if (!squashfs_get_cached_block(i->i_sb, (char *)
  1847. + dire, next_block, next_offset,
  1848. + sizeof(*dire), &next_block,
  1849. + &next_offset))
  1850. + goto failed_read;
  1851. +
  1852. + length += sizeof(*dire);
  1853. + }
  1854. +
  1855. + if (!squashfs_get_cached_block(i->i_sb, dire->name,
  1856. + next_block, next_offset,
  1857. + dire->size + 1, &next_block,
  1858. + &next_offset))
  1859. + goto failed_read;
  1860. +
  1861. + length += dire->size + 1;
  1862. +
  1863. + if (file->f_pos >= length)
  1864. + continue;
  1865. +
  1866. + dire->name[dire->size + 1] = '\0';
  1867. +
  1868. + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d, %d)\n",
  1869. + (unsigned int) dirent, dire->name,
  1870. + dire->size + 1, (int) file->f_pos,
  1871. + dirh.start_block, dire->offset,
  1872. + dirh.inode_number + dire->inode_number,
  1873. + squashfs_filetype_table[dire->type]);
  1874. +
  1875. + if (filldir(dirent, dire->name, dire->size + 1,
  1876. + file->f_pos,
  1877. + dirh.inode_number + dire->inode_number,
  1878. + squashfs_filetype_table[dire->type])
  1879. + < 0) {
  1880. + TRACE("Filldir returned less than 0\n");
  1881. + goto finish;
  1882. + }
  1883. + file->f_pos = length;
  1884. + dirs_read++;
  1885. + }
  1886. + }
  1887. +
  1888. +finish:
  1889. + return dirs_read;
  1890. +
  1891. +failed_read:
  1892. + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
  1893. + next_offset);
  1894. + return 0;
  1895. +}
  1896. +
  1897. +
  1898. +static struct dentry *squashfs_lookup(struct inode *i, struct dentry *dentry)
  1899. +{
  1900. + const unsigned char *name = dentry->d_name.name;
  1901. + int len = dentry->d_name.len;
  1902. + struct inode *inode = NULL;
  1903. + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
  1904. + struct squashfs_super_block *sblk = &msblk->sblk;
  1905. + long long next_block = SQUASHFS_I(i)->start_block +
  1906. + sblk->directory_table_start;
  1907. + int next_offset = SQUASHFS_I(i)->offset, length = 0,
  1908. + dir_count;
  1909. + struct squashfs_dir_header dirh;
  1910. + char buffer[sizeof(struct squashfs_dir_entry) + SQUASHFS_NAME_LEN];
  1911. + struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer;
  1912. +
  1913. + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
  1914. +
  1915. + if (len > SQUASHFS_NAME_LEN)
  1916. + goto exit_loop;
  1917. +
  1918. + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
  1919. + SQUASHFS_I(i)->u.s2.directory_index_start,
  1920. + SQUASHFS_I(i)->u.s2.directory_index_offset,
  1921. + SQUASHFS_I(i)->u.s2.directory_index_count, name,
  1922. + len);
  1923. +
  1924. + while (length < i_size_read(i)) {
  1925. + /* read directory header */
  1926. + if (msblk->swap) {
  1927. + struct squashfs_dir_header sdirh;
  1928. + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
  1929. + next_block, next_offset, sizeof(sdirh),
  1930. + &next_block, &next_offset))
  1931. + goto failed_read;
  1932. +
  1933. + length += sizeof(sdirh);
  1934. + SQUASHFS_SWAP_DIR_HEADER(&dirh, &sdirh);
  1935. + } else {
  1936. + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
  1937. + next_block, next_offset, sizeof(dirh),
  1938. + &next_block, &next_offset))
  1939. + goto failed_read;
  1940. +
  1941. + length += sizeof(dirh);
  1942. + }
  1943. +
  1944. + dir_count = dirh.count + 1;
  1945. + while (dir_count--) {
  1946. + if (msblk->swap) {
  1947. + struct squashfs_dir_entry sdire;
  1948. + if (!squashfs_get_cached_block(i->i_sb, (char *)
  1949. + &sdire, next_block,next_offset,
  1950. + sizeof(sdire), &next_block,
  1951. + &next_offset))
  1952. + goto failed_read;
  1953. +
  1954. + length += sizeof(sdire);
  1955. + SQUASHFS_SWAP_DIR_ENTRY(dire, &sdire);
  1956. + } else {
  1957. + if (!squashfs_get_cached_block(i->i_sb, (char *)
  1958. + dire, next_block,next_offset,
  1959. + sizeof(*dire), &next_block,
  1960. + &next_offset))
  1961. + goto failed_read;
  1962. +
  1963. + length += sizeof(*dire);
  1964. + }
  1965. +
  1966. + if (!squashfs_get_cached_block(i->i_sb, dire->name,
  1967. + next_block, next_offset, dire->size + 1,
  1968. + &next_block, &next_offset))
  1969. + goto failed_read;
  1970. +
  1971. + length += dire->size + 1;
  1972. +
  1973. + if (name[0] < dire->name[0])
  1974. + goto exit_loop;
  1975. +
  1976. + if ((len == dire->size + 1) && !strncmp(name,
  1977. + dire->name, len)) {
  1978. + squashfs_inode_t ino =
  1979. + SQUASHFS_MKINODE(dirh.start_block,
  1980. + dire->offset);
  1981. +
  1982. + TRACE("calling squashfs_iget for directory "
  1983. + "entry %s, inode %x:%x, %d\n", name,
  1984. + dirh.start_block, dire->offset,
  1985. + dirh.inode_number + dire->inode_number);
  1986. +
  1987. + inode = (msblk->iget)(i->i_sb, ino);
  1988. +
  1989. + goto exit_loop;
  1990. + }
  1991. + }
  1992. + }
  1993. +
  1994. +exit_loop:
  1995. + d_add(dentry, inode);
  1996. + return ERR_PTR(0);
  1997. +
  1998. +failed_read:
  1999. + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
  2000. + next_offset);
  2001. + goto exit_loop;
  2002. +}
  2003. +
  2004. +
  2005. +static void squashfs_put_super(struct super_block *s)
  2006. +{
  2007. + int i;
  2008. +
  2009. + struct squashfs_sb_info *sbi = &s->u.squashfs_sb;
  2010. + if (sbi->block_cache)
  2011. + for (i = 0; i < SQUASHFS_CACHED_BLKS; i++)
  2012. + if (sbi->block_cache[i].block !=
  2013. + SQUASHFS_INVALID_BLK)
  2014. + kfree(sbi->block_cache[i].data);
  2015. + if (sbi->fragment)
  2016. + for (i = 0; i < SQUASHFS_CACHED_FRAGMENTS; i++)
  2017. + SQUASHFS_FREE(sbi->fragment[i].data);
  2018. + kfree(sbi->fragment);
  2019. + kfree(sbi->block_cache);
  2020. + kfree(sbi->read_data);
  2021. + kfree(sbi->read_page);
  2022. + kfree(sbi->uid);
  2023. + kfree(sbi->fragment_index);
  2024. + kfree(sbi->fragment_index_2);
  2025. + sbi->block_cache = NULL;
  2026. + sbi->uid = NULL;
  2027. + sbi->read_data = NULL;
  2028. + sbi->read_page = NULL;
  2029. + sbi->fragment = NULL;
  2030. + sbi->fragment_index = NULL;
  2031. + sbi->fragment_index_2 = NULL;
  2032. +}
  2033. +
  2034. +
  2035. +static int __init init_squashfs_fs(void)
  2036. +{
  2037. +
  2038. + printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
  2039. + "Phillip Lougher\n");
  2040. +
  2041. + if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
  2042. + ERROR("Failed to allocate zlib workspace\n");
  2043. + return -ENOMEM;
  2044. + }
  2045. + return register_filesystem(&squashfs_fs_type);
  2046. +}
  2047. +
  2048. +
  2049. +static void __exit exit_squashfs_fs(void)
  2050. +{
  2051. + vfree(stream.workspace);
  2052. + unregister_filesystem(&squashfs_fs_type);
  2053. +}
  2054. +
  2055. +
  2056. +EXPORT_NO_SYMBOLS;
  2057. +
  2058. +module_init(init_squashfs_fs);
  2059. +module_exit(exit_squashfs_fs);
  2060. +MODULE_DESCRIPTION("squashfs, a compressed read-only filesystem");
  2061. +MODULE_AUTHOR("Phillip Lougher <[email protected]>");
  2062. +MODULE_LICENSE("GPL");
  2063. Index: linux-2.4.35.4/fs/squashfs/Makefile
  2064. ===================================================================
  2065. --- /dev/null
  2066. +++ linux-2.4.35.4/fs/squashfs/Makefile
  2067. @@ -0,0 +1,11 @@
  2068. +#
  2069. +# Makefile for the linux squashfs routines.
  2070. +#
  2071. +
  2072. +O_TARGET := squashfs.o
  2073. +
  2074. +obj-y := inode.o squashfs2_0.o
  2075. +
  2076. +obj-m := $(O_TARGET)
  2077. +
  2078. +include $(TOPDIR)/Rules.make
  2079. Index: linux-2.4.35.4/fs/squashfs/squashfs2_0.c
  2080. ===================================================================
  2081. --- /dev/null
  2082. +++ linux-2.4.35.4/fs/squashfs/squashfs2_0.c
  2083. @@ -0,0 +1,751 @@
  2084. +/*
  2085. + * Squashfs - a compressed read only filesystem for Linux
  2086. + *
  2087. + * Copyright (c) 2002, 2003, 2004, 2005, 2006
  2088. + * Phillip Lougher <[email protected]>
  2089. + *
  2090. + * This program is free software; you can redistribute it and/or
  2091. + * modify it under the terms of the GNU General Public License
  2092. + * as published by the Free Software Foundation; either version 2,
  2093. + * or (at your option) any later version.
  2094. + *
  2095. + * This program is distributed in the hope that it will be useful,
  2096. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2097. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2098. + * GNU General Public License for more details.
  2099. + *
  2100. + * You should have received a copy of the GNU General Public License
  2101. + * along with this program; if not, write to the Free Software
  2102. + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  2103. + *
  2104. + * squashfs2_0.c
  2105. + */
  2106. +
  2107. +#include <linux/types.h>
  2108. +#include <linux/squashfs_fs.h>
  2109. +#include <linux/module.h>
  2110. +#include <linux/errno.h>
  2111. +#include <linux/slab.h>
  2112. +#include <linux/fs.h>
  2113. +#include <linux/smp_lock.h>
  2114. +#include <linux/locks.h>
  2115. +#include <linux/init.h>
  2116. +#include <linux/dcache.h>
  2117. +#include <linux/wait.h>
  2118. +#include <linux/zlib.h>
  2119. +#include <linux/blkdev.h>
  2120. +#include <linux/vmalloc.h>
  2121. +#include <asm/uaccess.h>
  2122. +#include <asm/semaphore.h>
  2123. +#include "squashfs.h"
  2124. +
  2125. +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir);
  2126. +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry);
  2127. +
  2128. +static struct file_operations squashfs_dir_ops_2 = {
  2129. + .read = generic_read_dir,
  2130. + .readdir = squashfs_readdir_2
  2131. +};
  2132. +
  2133. +static struct inode_operations squashfs_dir_inode_ops_2 = {
  2134. + .lookup = squashfs_lookup_2
  2135. +};
  2136. +
  2137. +static unsigned char squashfs_filetype_table[] = {
  2138. + DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_FIFO, DT_SOCK
  2139. +};
  2140. +
  2141. +static int read_fragment_index_table_2(struct super_block *s)
  2142. +{
  2143. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  2144. + struct squashfs_super_block *sblk = &msblk->sblk;
  2145. +
  2146. + if (!(msblk->fragment_index_2 = kmalloc(SQUASHFS_FRAGMENT_INDEX_BYTES_2
  2147. + (sblk->fragments), GFP_KERNEL))) {
  2148. + ERROR("Failed to allocate uid/gid table\n");
  2149. + return 0;
  2150. + }
  2151. +
  2152. + if (SQUASHFS_FRAGMENT_INDEX_BYTES_2(sblk->fragments) &&
  2153. + !squashfs_read_data(s, (char *)
  2154. + msblk->fragment_index_2,
  2155. + sblk->fragment_table_start,
  2156. + SQUASHFS_FRAGMENT_INDEX_BYTES_2
  2157. + (sblk->fragments) |
  2158. + SQUASHFS_COMPRESSED_BIT_BLOCK, NULL)) {
  2159. + ERROR("unable to read fragment index table\n");
  2160. + return 0;
  2161. + }
  2162. +
  2163. + if (msblk->swap) {
  2164. + int i;
  2165. + unsigned int fragment;
  2166. +
  2167. + for (i = 0; i < SQUASHFS_FRAGMENT_INDEXES_2(sblk->fragments);
  2168. + i++) {
  2169. + SQUASHFS_SWAP_FRAGMENT_INDEXES_2((&fragment),
  2170. + &msblk->fragment_index_2[i], 1);
  2171. + msblk->fragment_index_2[i] = fragment;
  2172. + }
  2173. + }
  2174. +
  2175. + return 1;
  2176. +}
  2177. +
  2178. +
  2179. +static int get_fragment_location_2(struct super_block *s, unsigned int fragment,
  2180. + long long *fragment_start_block,
  2181. + unsigned int *fragment_size)
  2182. +{
  2183. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  2184. + long long start_block =
  2185. + msblk->fragment_index_2[SQUASHFS_FRAGMENT_INDEX_2(fragment)];
  2186. + int offset = SQUASHFS_FRAGMENT_INDEX_OFFSET_2(fragment);
  2187. + struct squashfs_fragment_entry_2 fragment_entry;
  2188. +
  2189. + if (msblk->swap) {
  2190. + struct squashfs_fragment_entry_2 sfragment_entry;
  2191. +
  2192. + if (!squashfs_get_cached_block(s, (char *) &sfragment_entry,
  2193. + start_block, offset,
  2194. + sizeof(sfragment_entry), &start_block,
  2195. + &offset))
  2196. + goto out;
  2197. + SQUASHFS_SWAP_FRAGMENT_ENTRY_2(&fragment_entry, &sfragment_entry);
  2198. + } else
  2199. + if (!squashfs_get_cached_block(s, (char *) &fragment_entry,
  2200. + start_block, offset,
  2201. + sizeof(fragment_entry), &start_block,
  2202. + &offset))
  2203. + goto out;
  2204. +
  2205. + *fragment_start_block = fragment_entry.start_block;
  2206. + *fragment_size = fragment_entry.size;
  2207. +
  2208. + return 1;
  2209. +
  2210. +out:
  2211. + return 0;
  2212. +}
  2213. +
  2214. +
  2215. +static struct inode *squashfs_new_inode(struct super_block *s,
  2216. + struct squashfs_base_inode_header_2 *inodeb, unsigned int ino)
  2217. +{
  2218. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  2219. + struct squashfs_super_block *sblk = &msblk->sblk;
  2220. + struct inode *i = new_inode(s);
  2221. +
  2222. + if (i) {
  2223. + i->i_ino = ino;
  2224. + i->i_mtime = sblk->mkfs_time;
  2225. + i->i_atime = sblk->mkfs_time;
  2226. + i->i_ctime = sblk->mkfs_time;
  2227. + i->i_uid = msblk->uid[inodeb->uid];
  2228. + i->i_mode = inodeb->mode;
  2229. + i->i_nlink = 1;
  2230. + i->i_size = 0;
  2231. + if (inodeb->guid == SQUASHFS_GUIDS)
  2232. + i->i_gid = i->i_uid;
  2233. + else
  2234. + i->i_gid = msblk->guid[inodeb->guid];
  2235. + }
  2236. +
  2237. + return i;
  2238. +}
  2239. +
  2240. +
  2241. +static struct inode *squashfs_iget_2(struct super_block *s, squashfs_inode_t inode)
  2242. +{
  2243. + struct inode *i;
  2244. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  2245. + struct squashfs_super_block *sblk = &msblk->sblk;
  2246. + unsigned int block = SQUASHFS_INODE_BLK(inode) +
  2247. + sblk->inode_table_start;
  2248. + unsigned int offset = SQUASHFS_INODE_OFFSET(inode);
  2249. + unsigned int ino = SQUASHFS_MK_VFS_INODE(block
  2250. + - sblk->inode_table_start, offset);
  2251. + long long next_block;
  2252. + unsigned int next_offset;
  2253. + union squashfs_inode_header_2 id, sid;
  2254. + struct squashfs_base_inode_header_2 *inodeb = &id.base,
  2255. + *sinodeb = &sid.base;
  2256. +
  2257. + TRACE("Entered squashfs_iget\n");
  2258. +
  2259. + if (msblk->swap) {
  2260. + if (!squashfs_get_cached_block(s, (char *) sinodeb, block,
  2261. + offset, sizeof(*sinodeb), &next_block,
  2262. + &next_offset))
  2263. + goto failed_read;
  2264. + SQUASHFS_SWAP_BASE_INODE_HEADER_2(inodeb, sinodeb,
  2265. + sizeof(*sinodeb));
  2266. + } else
  2267. + if (!squashfs_get_cached_block(s, (char *) inodeb, block,
  2268. + offset, sizeof(*inodeb), &next_block,
  2269. + &next_offset))
  2270. + goto failed_read;
  2271. +
  2272. + switch(inodeb->inode_type) {
  2273. + case SQUASHFS_FILE_TYPE: {
  2274. + struct squashfs_reg_inode_header_2 *inodep = &id.reg;
  2275. + struct squashfs_reg_inode_header_2 *sinodep = &sid.reg;
  2276. + long long frag_blk;
  2277. + unsigned int frag_size;
  2278. +
  2279. + if (msblk->swap) {
  2280. + if (!squashfs_get_cached_block(s, (char *)
  2281. + sinodep, block, offset,
  2282. + sizeof(*sinodep), &next_block,
  2283. + &next_offset))
  2284. + goto failed_read;
  2285. + SQUASHFS_SWAP_REG_INODE_HEADER_2(inodep, sinodep);
  2286. + } else
  2287. + if (!squashfs_get_cached_block(s, (char *)
  2288. + inodep, block, offset,
  2289. + sizeof(*inodep), &next_block,
  2290. + &next_offset))
  2291. + goto failed_read;
  2292. +
  2293. + frag_blk = SQUASHFS_INVALID_BLK;
  2294. + if (inodep->fragment != SQUASHFS_INVALID_FRAG &&
  2295. + !get_fragment_location_2(s,
  2296. + inodep->fragment, &frag_blk, &frag_size))
  2297. + goto failed_read;
  2298. +
  2299. + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
  2300. + goto failed_read1;
  2301. +
  2302. + i->i_size = inodep->file_size;
  2303. + i->i_fop = &generic_ro_fops;
  2304. + i->i_mode |= S_IFREG;
  2305. + i->i_mtime = inodep->mtime;
  2306. + i->i_atime = inodep->mtime;
  2307. + i->i_ctime = inodep->mtime;
  2308. + i->i_blocks = ((i->i_size - 1) >> 9) + 1;
  2309. + i->i_blksize = PAGE_CACHE_SIZE;
  2310. + SQUASHFS_I(i)->u.s1.fragment_start_block = frag_blk;
  2311. + SQUASHFS_I(i)->u.s1.fragment_size = frag_size;
  2312. + SQUASHFS_I(i)->u.s1.fragment_offset = inodep->offset;
  2313. + SQUASHFS_I(i)->start_block = inodep->start_block;
  2314. + SQUASHFS_I(i)->u.s1.block_list_start = next_block;
  2315. + SQUASHFS_I(i)->offset = next_offset;
  2316. + if (sblk->block_size > 4096)
  2317. + i->i_data.a_ops = &squashfs_aops;
  2318. + else
  2319. + i->i_data.a_ops = &squashfs_aops_4K;
  2320. +
  2321. + TRACE("File inode %x:%x, start_block %x, "
  2322. + "block_list_start %llx, offset %x\n",
  2323. + SQUASHFS_INODE_BLK(inode), offset,
  2324. + inodep->start_block, next_block,
  2325. + next_offset);
  2326. + break;
  2327. + }
  2328. + case SQUASHFS_DIR_TYPE: {
  2329. + struct squashfs_dir_inode_header_2 *inodep = &id.dir;
  2330. + struct squashfs_dir_inode_header_2 *sinodep = &sid.dir;
  2331. +
  2332. + if (msblk->swap) {
  2333. + if (!squashfs_get_cached_block(s, (char *)
  2334. + sinodep, block, offset,
  2335. + sizeof(*sinodep), &next_block,
  2336. + &next_offset))
  2337. + goto failed_read;
  2338. + SQUASHFS_SWAP_DIR_INODE_HEADER_2(inodep, sinodep);
  2339. + } else
  2340. + if (!squashfs_get_cached_block(s, (char *)
  2341. + inodep, block, offset,
  2342. + sizeof(*inodep), &next_block,
  2343. + &next_offset))
  2344. + goto failed_read;
  2345. +
  2346. + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
  2347. + goto failed_read1;
  2348. +
  2349. + i->i_size = inodep->file_size;
  2350. + i->i_op = &squashfs_dir_inode_ops_2;
  2351. + i->i_fop = &squashfs_dir_ops_2;
  2352. + i->i_mode |= S_IFDIR;
  2353. + i->i_mtime = inodep->mtime;
  2354. + i->i_atime = inodep->mtime;
  2355. + i->i_ctime = inodep->mtime;
  2356. + SQUASHFS_I(i)->start_block = inodep->start_block;
  2357. + SQUASHFS_I(i)->offset = inodep->offset;
  2358. + SQUASHFS_I(i)->u.s2.directory_index_count = 0;
  2359. + SQUASHFS_I(i)->u.s2.parent_inode = 0;
  2360. +
  2361. + TRACE("Directory inode %x:%x, start_block %x, offset "
  2362. + "%x\n", SQUASHFS_INODE_BLK(inode),
  2363. + offset, inodep->start_block,
  2364. + inodep->offset);
  2365. + break;
  2366. + }
  2367. + case SQUASHFS_LDIR_TYPE: {
  2368. + struct squashfs_ldir_inode_header_2 *inodep = &id.ldir;
  2369. + struct squashfs_ldir_inode_header_2 *sinodep = &sid.ldir;
  2370. +
  2371. + if (msblk->swap) {
  2372. + if (!squashfs_get_cached_block(s, (char *)
  2373. + sinodep, block, offset,
  2374. + sizeof(*sinodep), &next_block,
  2375. + &next_offset))
  2376. + goto failed_read;
  2377. + SQUASHFS_SWAP_LDIR_INODE_HEADER_2(inodep,
  2378. + sinodep);
  2379. + } else
  2380. + if (!squashfs_get_cached_block(s, (char *)
  2381. + inodep, block, offset,
  2382. + sizeof(*inodep), &next_block,
  2383. + &next_offset))
  2384. + goto failed_read;
  2385. +
  2386. + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
  2387. + goto failed_read1;
  2388. +
  2389. + i->i_size = inodep->file_size;
  2390. + i->i_op = &squashfs_dir_inode_ops_2;
  2391. + i->i_fop = &squashfs_dir_ops_2;
  2392. + i->i_mode |= S_IFDIR;
  2393. + i->i_mtime = inodep->mtime;
  2394. + i->i_atime = inodep->mtime;
  2395. + i->i_ctime = inodep->mtime;
  2396. + SQUASHFS_I(i)->start_block = inodep->start_block;
  2397. + SQUASHFS_I(i)->offset = inodep->offset;
  2398. + SQUASHFS_I(i)->u.s2.directory_index_start = next_block;
  2399. + SQUASHFS_I(i)->u.s2.directory_index_offset =
  2400. + next_offset;
  2401. + SQUASHFS_I(i)->u.s2.directory_index_count =
  2402. + inodep->i_count;
  2403. + SQUASHFS_I(i)->u.s2.parent_inode = 0;
  2404. +
  2405. + TRACE("Long directory inode %x:%x, start_block %x, "
  2406. + "offset %x\n",
  2407. + SQUASHFS_INODE_BLK(inode), offset,
  2408. + inodep->start_block, inodep->offset);
  2409. + break;
  2410. + }
  2411. + case SQUASHFS_SYMLINK_TYPE: {
  2412. + struct squashfs_symlink_inode_header_2 *inodep =
  2413. + &id.symlink;
  2414. + struct squashfs_symlink_inode_header_2 *sinodep =
  2415. + &sid.symlink;
  2416. +
  2417. + if (msblk->swap) {
  2418. + if (!squashfs_get_cached_block(s, (char *)
  2419. + sinodep, block, offset,
  2420. + sizeof(*sinodep), &next_block,
  2421. + &next_offset))
  2422. + goto failed_read;
  2423. + SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(inodep,
  2424. + sinodep);
  2425. + } else
  2426. + if (!squashfs_get_cached_block(s, (char *)
  2427. + inodep, block, offset,
  2428. + sizeof(*inodep), &next_block,
  2429. + &next_offset))
  2430. + goto failed_read;
  2431. +
  2432. + if((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
  2433. + goto failed_read1;
  2434. +
  2435. + i->i_size = inodep->symlink_size;
  2436. + i->i_op = &page_symlink_inode_operations;
  2437. + i->i_data.a_ops = &squashfs_symlink_aops;
  2438. + i->i_mode |= S_IFLNK;
  2439. + SQUASHFS_I(i)->start_block = next_block;
  2440. + SQUASHFS_I(i)->offset = next_offset;
  2441. +
  2442. + TRACE("Symbolic link inode %x:%x, start_block %llx, "
  2443. + "offset %x\n",
  2444. + SQUASHFS_INODE_BLK(inode), offset,
  2445. + next_block, next_offset);
  2446. + break;
  2447. + }
  2448. + case SQUASHFS_BLKDEV_TYPE:
  2449. + case SQUASHFS_CHRDEV_TYPE: {
  2450. + struct squashfs_dev_inode_header_2 *inodep = &id.dev;
  2451. + struct squashfs_dev_inode_header_2 *sinodep = &sid.dev;
  2452. +
  2453. + if (msblk->swap) {
  2454. + if (!squashfs_get_cached_block(s, (char *)
  2455. + sinodep, block, offset,
  2456. + sizeof(*sinodep), &next_block,
  2457. + &next_offset))
  2458. + goto failed_read;
  2459. + SQUASHFS_SWAP_DEV_INODE_HEADER_2(inodep, sinodep);
  2460. + } else
  2461. + if (!squashfs_get_cached_block(s, (char *)
  2462. + inodep, block, offset,
  2463. + sizeof(*inodep), &next_block,
  2464. + &next_offset))
  2465. + goto failed_read;
  2466. +
  2467. + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
  2468. + goto failed_read1;
  2469. +
  2470. + i->i_mode |= (inodeb->inode_type ==
  2471. + SQUASHFS_CHRDEV_TYPE) ? S_IFCHR :
  2472. + S_IFBLK;
  2473. + init_special_inode(i, i->i_mode, inodep->rdev);
  2474. +
  2475. + TRACE("Device inode %x:%x, rdev %x\n",
  2476. + SQUASHFS_INODE_BLK(inode), offset,
  2477. + inodep->rdev);
  2478. + break;
  2479. + }
  2480. + case SQUASHFS_FIFO_TYPE:
  2481. + case SQUASHFS_SOCKET_TYPE: {
  2482. + if ((i = squashfs_new_inode(s, inodeb, ino)) == NULL)
  2483. + goto failed_read1;
  2484. +
  2485. + i->i_mode |= (inodeb->inode_type == SQUASHFS_FIFO_TYPE)
  2486. + ? S_IFIFO : S_IFSOCK;
  2487. + init_special_inode(i, i->i_mode, 0);
  2488. + break;
  2489. + }
  2490. + default:
  2491. + ERROR("Unknown inode type %d in squashfs_iget!\n",
  2492. + inodeb->inode_type);
  2493. + goto failed_read1;
  2494. + }
  2495. +
  2496. + insert_inode_hash(i);
  2497. + return i;
  2498. +
  2499. +failed_read:
  2500. + ERROR("Unable to read inode [%x:%x]\n", block, offset);
  2501. +
  2502. +failed_read1:
  2503. + return NULL;
  2504. +}
  2505. +
  2506. +
  2507. +static int get_dir_index_using_offset(struct super_block *s, long long
  2508. + *next_block, unsigned int *next_offset,
  2509. + long long index_start,
  2510. + unsigned int index_offset, int i_count,
  2511. + long long f_pos)
  2512. +{
  2513. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  2514. + struct squashfs_super_block *sblk = &msblk->sblk;
  2515. + int i, length = 0;
  2516. + struct squashfs_dir_index_2 index;
  2517. +
  2518. + TRACE("Entered get_dir_index_using_offset, i_count %d, f_pos %d\n",
  2519. + i_count, (unsigned int) f_pos);
  2520. +
  2521. + if (f_pos == 0)
  2522. + goto finish;
  2523. +
  2524. + for (i = 0; i < i_count; i++) {
  2525. + if (msblk->swap) {
  2526. + struct squashfs_dir_index_2 sindex;
  2527. + squashfs_get_cached_block(s, (char *) &sindex,
  2528. + index_start, index_offset,
  2529. + sizeof(sindex), &index_start,
  2530. + &index_offset);
  2531. + SQUASHFS_SWAP_DIR_INDEX_2(&index, &sindex);
  2532. + } else
  2533. + squashfs_get_cached_block(s, (char *) &index,
  2534. + index_start, index_offset,
  2535. + sizeof(index), &index_start,
  2536. + &index_offset);
  2537. +
  2538. + if (index.index > f_pos)
  2539. + break;
  2540. +
  2541. + squashfs_get_cached_block(s, NULL, index_start, index_offset,
  2542. + index.size + 1, &index_start,
  2543. + &index_offset);
  2544. +
  2545. + length = index.index;
  2546. + *next_block = index.start_block + sblk->directory_table_start;
  2547. + }
  2548. +
  2549. + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
  2550. +
  2551. +finish:
  2552. + return length;
  2553. +}
  2554. +
  2555. +
  2556. +static int get_dir_index_using_name(struct super_block *s, long long
  2557. + *next_block, unsigned int *next_offset,
  2558. + long long index_start,
  2559. + unsigned int index_offset, int i_count,
  2560. + const char *name, int size)
  2561. +{
  2562. + struct squashfs_sb_info *msblk = &s->u.squashfs_sb;
  2563. + struct squashfs_super_block *sblk = &msblk->sblk;
  2564. + int i, length = 0;
  2565. + char buffer[sizeof(struct squashfs_dir_index_2) + SQUASHFS_NAME_LEN + 1];
  2566. + struct squashfs_dir_index_2 *index = (struct squashfs_dir_index_2 *) buffer;
  2567. + char str[SQUASHFS_NAME_LEN + 1];
  2568. +
  2569. + TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count);
  2570. +
  2571. + strncpy(str, name, size);
  2572. + str[size] = '\0';
  2573. +
  2574. + for (i = 0; i < i_count; i++) {
  2575. + if (msblk->swap) {
  2576. + struct squashfs_dir_index_2 sindex;
  2577. + squashfs_get_cached_block(s, (char *) &sindex,
  2578. + index_start, index_offset,
  2579. + sizeof(sindex), &index_start,
  2580. + &index_offset);
  2581. + SQUASHFS_SWAP_DIR_INDEX_2(index, &sindex);
  2582. + } else
  2583. + squashfs_get_cached_block(s, (char *) index,
  2584. + index_start, index_offset,
  2585. + sizeof(struct squashfs_dir_index_2),
  2586. + &index_start, &index_offset);
  2587. +
  2588. + squashfs_get_cached_block(s, index->name, index_start,
  2589. + index_offset, index->size + 1,
  2590. + &index_start, &index_offset);
  2591. +
  2592. + index->name[index->size + 1] = '\0';
  2593. +
  2594. + if (strcmp(index->name, str) > 0)
  2595. + break;
  2596. +
  2597. + length = index->index;
  2598. + *next_block = index->start_block + sblk->directory_table_start;
  2599. + }
  2600. +
  2601. + *next_offset = (length + *next_offset) % SQUASHFS_METADATA_SIZE;
  2602. + return length;
  2603. +}
  2604. +
  2605. +
  2606. +static int squashfs_readdir_2(struct file *file, void *dirent, filldir_t filldir)
  2607. +{
  2608. + struct inode *i = file->f_dentry->d_inode;
  2609. + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
  2610. + struct squashfs_super_block *sblk = &msblk->sblk;
  2611. + long long next_block = SQUASHFS_I(i)->start_block +
  2612. + sblk->directory_table_start;
  2613. + int next_offset = SQUASHFS_I(i)->offset, length = 0, dirs_read = 0,
  2614. + dir_count;
  2615. + struct squashfs_dir_header_2 dirh;
  2616. + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN + 1];
  2617. + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
  2618. +
  2619. + TRACE("Entered squashfs_readdir_2 [%llx:%x]\n", next_block, next_offset);
  2620. +
  2621. + length = get_dir_index_using_offset(i->i_sb, &next_block, &next_offset,
  2622. + SQUASHFS_I(i)->u.s2.directory_index_start,
  2623. + SQUASHFS_I(i)->u.s2.directory_index_offset,
  2624. + SQUASHFS_I(i)->u.s2.directory_index_count,
  2625. + file->f_pos);
  2626. +
  2627. + while (length < i_size_read(i)) {
  2628. + /* read directory header */
  2629. + if (msblk->swap) {
  2630. + struct squashfs_dir_header_2 sdirh;
  2631. +
  2632. + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
  2633. + next_block, next_offset, sizeof(sdirh),
  2634. + &next_block, &next_offset))
  2635. + goto failed_read;
  2636. +
  2637. + length += sizeof(sdirh);
  2638. + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
  2639. + } else {
  2640. + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
  2641. + next_block, next_offset, sizeof(dirh),
  2642. + &next_block, &next_offset))
  2643. + goto failed_read;
  2644. +
  2645. + length += sizeof(dirh);
  2646. + }
  2647. +
  2648. + dir_count = dirh.count + 1;
  2649. + while (dir_count--) {
  2650. + if (msblk->swap) {
  2651. + struct squashfs_dir_entry_2 sdire;
  2652. + if (!squashfs_get_cached_block(i->i_sb, (char *)
  2653. + &sdire, next_block, next_offset,
  2654. + sizeof(sdire), &next_block,
  2655. + &next_offset))
  2656. + goto failed_read;
  2657. +
  2658. + length += sizeof(sdire);
  2659. + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
  2660. + } else {
  2661. + if (!squashfs_get_cached_block(i->i_sb, (char *)
  2662. + dire, next_block, next_offset,
  2663. + sizeof(*dire), &next_block,
  2664. + &next_offset))
  2665. + goto failed_read;
  2666. +
  2667. + length += sizeof(*dire);
  2668. + }
  2669. +
  2670. + if (!squashfs_get_cached_block(i->i_sb, dire->name,
  2671. + next_block, next_offset,
  2672. + dire->size + 1, &next_block,
  2673. + &next_offset))
  2674. + goto failed_read;
  2675. +
  2676. + length += dire->size + 1;
  2677. +
  2678. + if (file->f_pos >= length)
  2679. + continue;
  2680. +
  2681. + dire->name[dire->size + 1] = '\0';
  2682. +
  2683. + TRACE("Calling filldir(%x, %s, %d, %d, %x:%x, %d)\n",
  2684. + (unsigned int) dirent, dire->name,
  2685. + dire->size + 1, (int) file->f_pos,
  2686. + dirh.start_block, dire->offset,
  2687. + squashfs_filetype_table[dire->type]);
  2688. +
  2689. + if (filldir(dirent, dire->name, dire->size + 1,
  2690. + file->f_pos, SQUASHFS_MK_VFS_INODE(
  2691. + dirh.start_block, dire->offset),
  2692. + squashfs_filetype_table[dire->type])
  2693. + < 0) {
  2694. + TRACE("Filldir returned less than 0\n");
  2695. + goto finish;
  2696. + }
  2697. + file->f_pos = length;
  2698. + dirs_read++;
  2699. + }
  2700. + }
  2701. +
  2702. +finish:
  2703. + return dirs_read;
  2704. +
  2705. +failed_read:
  2706. + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
  2707. + next_offset);
  2708. + return 0;
  2709. +}
  2710. +
  2711. +
  2712. +static struct dentry *squashfs_lookup_2(struct inode *i, struct dentry *dentry)
  2713. +{
  2714. + const unsigned char *name = dentry->d_name.name;
  2715. + int len = dentry->d_name.len;
  2716. + struct inode *inode = NULL;
  2717. + struct squashfs_sb_info *msblk = &i->i_sb->u.squashfs_sb;
  2718. + struct squashfs_super_block *sblk = &msblk->sblk;
  2719. + long long next_block = SQUASHFS_I(i)->start_block +
  2720. + sblk->directory_table_start;
  2721. + int next_offset = SQUASHFS_I(i)->offset, length = 0,
  2722. + dir_count;
  2723. + struct squashfs_dir_header_2 dirh;
  2724. + char buffer[sizeof(struct squashfs_dir_entry_2) + SQUASHFS_NAME_LEN];
  2725. + struct squashfs_dir_entry_2 *dire = (struct squashfs_dir_entry_2 *) buffer;
  2726. + int sorted = sblk->s_major == 2 && sblk->s_minor >= 1;
  2727. +
  2728. + TRACE("Entered squashfs_lookup [%llx:%x]\n", next_block, next_offset);
  2729. +
  2730. + if (len > SQUASHFS_NAME_LEN)
  2731. + goto exit_loop;
  2732. +
  2733. + length = get_dir_index_using_name(i->i_sb, &next_block, &next_offset,
  2734. + SQUASHFS_I(i)->u.s2.directory_index_start,
  2735. + SQUASHFS_I(i)->u.s2.directory_index_offset,
  2736. + SQUASHFS_I(i)->u.s2.directory_index_count, name,
  2737. + len);
  2738. +
  2739. + while (length < i_size_read(i)) {
  2740. + /* read directory header */
  2741. + if (msblk->swap) {
  2742. + struct squashfs_dir_header_2 sdirh;
  2743. + if (!squashfs_get_cached_block(i->i_sb, (char *) &sdirh,
  2744. + next_block, next_offset, sizeof(sdirh),
  2745. + &next_block, &next_offset))
  2746. + goto failed_read;
  2747. +
  2748. + length += sizeof(sdirh);
  2749. + SQUASHFS_SWAP_DIR_HEADER_2(&dirh, &sdirh);
  2750. + } else {
  2751. + if (!squashfs_get_cached_block(i->i_sb, (char *) &dirh,
  2752. + next_block, next_offset, sizeof(dirh),
  2753. + &next_block, &next_offset))
  2754. + goto failed_read;
  2755. +
  2756. + length += sizeof(dirh);
  2757. + }
  2758. +
  2759. + dir_count = dirh.count + 1;
  2760. + while (dir_count--) {
  2761. + if (msblk->swap) {
  2762. + struct squashfs_dir_entry_2 sdire;
  2763. + if (!squashfs_get_cached_block(i->i_sb, (char *)
  2764. + &sdire, next_block,next_offset,
  2765. + sizeof(sdire), &next_block,
  2766. + &next_offset))
  2767. + goto failed_read;
  2768. +
  2769. + length += sizeof(sdire);
  2770. + SQUASHFS_SWAP_DIR_ENTRY_2(dire, &sdire);
  2771. + } else {
  2772. + if (!squashfs_get_cached_block(i->i_sb, (char *)
  2773. + dire, next_block,next_offset,
  2774. + sizeof(*dire), &next_block,
  2775. + &next_offset))
  2776. + goto failed_read;
  2777. +
  2778. + length += sizeof(*dire);
  2779. + }
  2780. +
  2781. + if (!squashfs_get_cached_block(i->i_sb, dire->name,
  2782. + next_block, next_offset, dire->size + 1,
  2783. + &next_block, &next_offset))
  2784. + goto failed_read;
  2785. +
  2786. + length += dire->size + 1;
  2787. +
  2788. + if (sorted && name[0] < dire->name[0])
  2789. + goto exit_loop;
  2790. +
  2791. + if ((len == dire->size + 1) && !strncmp(name,
  2792. + dire->name, len)) {
  2793. + squashfs_inode_t ino =
  2794. + SQUASHFS_MKINODE(dirh.start_block,
  2795. + dire->offset);
  2796. +
  2797. + TRACE("calling squashfs_iget for directory "
  2798. + "entry %s, inode %x:%x, %d\n", name,
  2799. + dirh.start_block, dire->offset, ino);
  2800. +
  2801. + inode = (msblk->iget)(i->i_sb, ino);
  2802. +
  2803. + goto exit_loop;
  2804. + }
  2805. + }
  2806. + }
  2807. +
  2808. +exit_loop:
  2809. + d_add(dentry, inode);
  2810. + return ERR_PTR(0);
  2811. +
  2812. +failed_read:
  2813. + ERROR("Unable to read directory block [%llx:%x]\n", next_block,
  2814. + next_offset);
  2815. + goto exit_loop;
  2816. +}
  2817. +
  2818. +
  2819. +int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
  2820. +{
  2821. + struct squashfs_super_block *sblk = &msblk->sblk;
  2822. +
  2823. + msblk->iget = squashfs_iget_2;
  2824. + msblk->read_fragment_index_table = read_fragment_index_table_2;
  2825. +
  2826. + sblk->bytes_used = sblk->bytes_used_2;
  2827. + sblk->uid_start = sblk->uid_start_2;
  2828. + sblk->guid_start = sblk->guid_start_2;
  2829. + sblk->inode_table_start = sblk->inode_table_start_2;
  2830. + sblk->directory_table_start = sblk->directory_table_start_2;
  2831. + sblk->fragment_table_start = sblk->fragment_table_start_2;
  2832. +
  2833. + return 1;
  2834. +}
  2835. Index: linux-2.4.35.4/fs/squashfs/squashfs.h
  2836. ===================================================================
  2837. --- /dev/null
  2838. +++ linux-2.4.35.4/fs/squashfs/squashfs.h
  2839. @@ -0,0 +1,85 @@
  2840. +/*
  2841. + * Squashfs - a compressed read only filesystem for Linux
  2842. + *
  2843. + * Copyright (c) 2002, 2003, 2004, 2005, 2006
  2844. + * Phillip Lougher <[email protected]>
  2845. + *
  2846. + * This program is free software; you can redistribute it and/or
  2847. + * modify it under the terms of the GNU General Public License
  2848. + * as published by the Free Software Foundation; either version 2,
  2849. + * or (at your option) any later version.
  2850. + *
  2851. + * This program is distributed in the hope that it will be useful,
  2852. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2853. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2854. + * GNU General Public License for more details.
  2855. + *
  2856. + * You should have received a copy of the GNU General Public License
  2857. + * along with this program; if not, write to the Free Software
  2858. + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  2859. + *
  2860. + * squashfs.h
  2861. + */
  2862. +
  2863. +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
  2864. +#undef CONFIG_SQUASHFS_1_0_COMPATIBILITY
  2865. +#endif
  2866. +#ifdef SQUASHFS_TRACE
  2867. +#define TRACE(s, args...) printk(KERN_NOTICE "SQUASHFS: "s, ## args)
  2868. +#else
  2869. +#define TRACE(s, args...) {}
  2870. +#endif
  2871. +
  2872. +#define ERROR(s, args...) printk(KERN_ERR "SQUASHFS error: "s, ## args)
  2873. +
  2874. +#define SERROR(s, args...) do { \
  2875. + if (!silent) \
  2876. + printk(KERN_ERR "SQUASHFS error: "s, ## args);\
  2877. + } while(0)
  2878. +
  2879. +#define WARNING(s, args...) printk(KERN_WARNING "SQUASHFS: "s, ## args)
  2880. +
  2881. +#define SQUASHFS_I(INO) (&INO->u.squashfs_i)
  2882. +
  2883. +#define i_size_read(INO) (INO->i_size)
  2884. +
  2885. +#if defined(CONFIG_SQUASHFS_1_0_COMPATIBILITY ) || defined(CONFIG_SQUASHFS_2_0_COMPATIBILITY)
  2886. +#define SQSH_EXTERN
  2887. +extern unsigned int squashfs_read_data(struct super_block *s, char *buffer,
  2888. + long long index, unsigned int length,
  2889. + long long *next_index);
  2890. +extern int squashfs_get_cached_block(struct super_block *s, char *buffer,
  2891. + long long block, unsigned int offset,
  2892. + int length, long long *next_block,
  2893. + unsigned int *next_offset);
  2894. +extern void release_cached_fragment(struct squashfs_sb_info *msblk, struct
  2895. + squashfs_fragment_cache *fragment);
  2896. +extern struct squashfs_fragment_cache *get_cached_fragment(struct super_block
  2897. + *s, long long start_block,
  2898. + int length);
  2899. +extern struct address_space_operations squashfs_symlink_aops;
  2900. +extern struct address_space_operations squashfs_aops;
  2901. +extern struct address_space_operations squashfs_aops_4K;
  2902. +extern struct file_operations squashfs_dir_ops;
  2903. +extern struct inode_operations squashfs_dir_inode_ops;
  2904. +#else
  2905. +#define SQSH_EXTERN static
  2906. +#endif
  2907. +
  2908. +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
  2909. +extern int squashfs_1_0_supported(struct squashfs_sb_info *msblk);
  2910. +#else
  2911. +static inline int squashfs_1_0_supported(struct squashfs_sb_info *msblk)
  2912. +{
  2913. + return 0;
  2914. +}
  2915. +#endif
  2916. +
  2917. +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
  2918. +extern int squashfs_2_0_supported(struct squashfs_sb_info *msblk);
  2919. +#else
  2920. +static inline int squashfs_2_0_supported(struct squashfs_sb_info *msblk)
  2921. +{
  2922. + return 0;
  2923. +}
  2924. +#endif
  2925. Index: linux-2.4.35.4/include/linux/fs.h
  2926. ===================================================================
  2927. --- linux-2.4.35.4.orig/include/linux/fs.h
  2928. +++ linux-2.4.35.4/include/linux/fs.h
  2929. @@ -324,6 +324,7 @@ extern void set_bh_page(struct buffer_he
  2930. #include <linux/usbdev_fs_i.h>
  2931. #include <linux/jffs2_fs_i.h>
  2932. #include <linux/cramfs_fs_sb.h>
  2933. +#include <linux/squashfs_fs_i.h>
  2934. /*
  2935. * Attribute flags. These should be or-ed together to figure out what
  2936. @@ -519,6 +520,7 @@ struct inode {
  2937. struct socket socket_i;
  2938. struct usbdev_inode_info usbdev_i;
  2939. struct jffs2_inode_info jffs2_i;
  2940. + struct squashfs_inode_info squashfs_i;
  2941. void *generic_ip;
  2942. } u;
  2943. };
  2944. @@ -734,6 +736,7 @@ struct nameidata {
  2945. #include <linux/usbdev_fs_sb.h>
  2946. #include <linux/cramfs_fs_sb.h>
  2947. #include <linux/jffs2_fs_sb.h>
  2948. +#include <linux/squashfs_fs_sb.h>
  2949. extern struct list_head super_blocks;
  2950. extern spinlock_t sb_lock;
  2951. @@ -793,6 +796,7 @@ struct super_block {
  2952. struct usbdev_sb_info usbdevfs_sb;
  2953. struct jffs2_sb_info jffs2_sb;
  2954. struct cramfs_sb_info cramfs_sb;
  2955. + struct squashfs_sb_info squashfs_sb;
  2956. void *generic_sbp;
  2957. } u;
  2958. /*
  2959. Index: linux-2.4.35.4/include/linux/squashfs_fs.h
  2960. ===================================================================
  2961. --- /dev/null
  2962. +++ linux-2.4.35.4/include/linux/squashfs_fs.h
  2963. @@ -0,0 +1,915 @@
  2964. +#ifndef SQUASHFS_FS
  2965. +#define SQUASHFS_FS
  2966. +
  2967. +/*
  2968. + * Squashfs
  2969. + *
  2970. + * Copyright (c) 2002, 2003, 2004, 2005, 2006
  2971. + * Phillip Lougher <[email protected]>
  2972. + *
  2973. + * This program is free software; you can redistribute it and/or
  2974. + * modify it under the terms of the GNU General Public License
  2975. + * as published by the Free Software Foundation; either version 2,
  2976. + * or (at your option) any later version.
  2977. + *
  2978. + * This program is distributed in the hope that it will be useful,
  2979. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2980. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2981. + * GNU General Public License for more details.
  2982. + *
  2983. + * You should have received a copy of the GNU General Public License
  2984. + * along with this program; if not, write to the Free Software
  2985. + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  2986. + *
  2987. + * squashfs_fs.h
  2988. + */
  2989. +
  2990. +#ifndef CONFIG_SQUASHFS_2_0_COMPATIBILITY
  2991. +#define CONFIG_SQUASHFS_2_0_COMPATIBILITY
  2992. +#endif
  2993. +
  2994. +#ifdef CONFIG_SQUASHFS_VMALLOC
  2995. +#define SQUASHFS_ALLOC(a) vmalloc(a)
  2996. +#define SQUASHFS_FREE(a) vfree(a)
  2997. +#else
  2998. +#define SQUASHFS_ALLOC(a) kmalloc(a, GFP_KERNEL)
  2999. +#define SQUASHFS_FREE(a) kfree(a)
  3000. +#endif
  3001. +#ifdef CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
  3002. +#define SQUASHFS_CACHED_FRAGMENTS CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
  3003. +#else
  3004. +#define SQUASHFS_CACHED_FRAGMENTS 3
  3005. +#endif
  3006. +#define SQUASHFS_MAJOR 3
  3007. +#define SQUASHFS_MINOR 0
  3008. +#define SQUASHFS_MAGIC 0x73717368
  3009. +#define SQUASHFS_MAGIC_SWAP 0x68737173
  3010. +#define SQUASHFS_START 0
  3011. +
  3012. +/* size of metadata (inode and directory) blocks */
  3013. +#define SQUASHFS_METADATA_SIZE 8192
  3014. +#define SQUASHFS_METADATA_LOG 13
  3015. +
  3016. +/* default size of data blocks */
  3017. +#define SQUASHFS_FILE_SIZE 65536
  3018. +#define SQUASHFS_FILE_LOG 16
  3019. +
  3020. +#define SQUASHFS_FILE_MAX_SIZE 65536
  3021. +
  3022. +/* Max number of uids and gids */
  3023. +#define SQUASHFS_UIDS 256
  3024. +#define SQUASHFS_GUIDS 255
  3025. +
  3026. +/* Max length of filename (not 255) */
  3027. +#define SQUASHFS_NAME_LEN 256
  3028. +
  3029. +#define SQUASHFS_INVALID ((long long) 0xffffffffffff)
  3030. +#define SQUASHFS_INVALID_FRAG ((unsigned int) 0xffffffff)
  3031. +#define SQUASHFS_INVALID_BLK ((long long) -1)
  3032. +#define SQUASHFS_USED_BLK ((long long) -2)
  3033. +
  3034. +/* Filesystem flags */
  3035. +#define SQUASHFS_NOI 0
  3036. +#define SQUASHFS_NOD 1
  3037. +#define SQUASHFS_CHECK 2
  3038. +#define SQUASHFS_NOF 3
  3039. +#define SQUASHFS_NO_FRAG 4
  3040. +#define SQUASHFS_ALWAYS_FRAG 5
  3041. +#define SQUASHFS_DUPLICATE 6
  3042. +
  3043. +#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
  3044. +
  3045. +#define SQUASHFS_UNCOMPRESSED_INODES(flags) SQUASHFS_BIT(flags, \
  3046. + SQUASHFS_NOI)
  3047. +
  3048. +#define SQUASHFS_UNCOMPRESSED_DATA(flags) SQUASHFS_BIT(flags, \
  3049. + SQUASHFS_NOD)
  3050. +
  3051. +#define SQUASHFS_UNCOMPRESSED_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
  3052. + SQUASHFS_NOF)
  3053. +
  3054. +#define SQUASHFS_NO_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
  3055. + SQUASHFS_NO_FRAG)
  3056. +
  3057. +#define SQUASHFS_ALWAYS_FRAGMENTS(flags) SQUASHFS_BIT(flags, \
  3058. + SQUASHFS_ALWAYS_FRAG)
  3059. +
  3060. +#define SQUASHFS_DUPLICATES(flags) SQUASHFS_BIT(flags, \
  3061. + SQUASHFS_DUPLICATE)
  3062. +
  3063. +#define SQUASHFS_CHECK_DATA(flags) SQUASHFS_BIT(flags, \
  3064. + SQUASHFS_CHECK)
  3065. +
  3066. +#define SQUASHFS_MKFLAGS(noi, nod, check_data, nof, no_frag, always_frag, \
  3067. + duplicate_checking) (noi | (nod << 1) | (check_data << 2) \
  3068. + | (nof << 3) | (no_frag << 4) | (always_frag << 5) | \
  3069. + (duplicate_checking << 6))
  3070. +
  3071. +/* Max number of types and file types */
  3072. +#define SQUASHFS_DIR_TYPE 1
  3073. +#define SQUASHFS_FILE_TYPE 2
  3074. +#define SQUASHFS_SYMLINK_TYPE 3
  3075. +#define SQUASHFS_BLKDEV_TYPE 4
  3076. +#define SQUASHFS_CHRDEV_TYPE 5
  3077. +#define SQUASHFS_FIFO_TYPE 6
  3078. +#define SQUASHFS_SOCKET_TYPE 7
  3079. +#define SQUASHFS_LDIR_TYPE 8
  3080. +#define SQUASHFS_LREG_TYPE 9
  3081. +
  3082. +/* 1.0 filesystem type definitions */
  3083. +#define SQUASHFS_TYPES 5
  3084. +#define SQUASHFS_IPC_TYPE 0
  3085. +
  3086. +/* Flag whether block is compressed or uncompressed, bit is set if block is
  3087. + * uncompressed */
  3088. +#define SQUASHFS_COMPRESSED_BIT (1 << 15)
  3089. +
  3090. +#define SQUASHFS_COMPRESSED_SIZE(B) (((B) & ~SQUASHFS_COMPRESSED_BIT) ? \
  3091. + (B) & ~SQUASHFS_COMPRESSED_BIT : SQUASHFS_COMPRESSED_BIT)
  3092. +
  3093. +#define SQUASHFS_COMPRESSED(B) (!((B) & SQUASHFS_COMPRESSED_BIT))
  3094. +
  3095. +#define SQUASHFS_COMPRESSED_BIT_BLOCK (1 << 24)
  3096. +
  3097. +#define SQUASHFS_COMPRESSED_SIZE_BLOCK(B) (((B) & \
  3098. + ~SQUASHFS_COMPRESSED_BIT_BLOCK) ? (B) & \
  3099. + ~SQUASHFS_COMPRESSED_BIT_BLOCK : SQUASHFS_COMPRESSED_BIT_BLOCK)
  3100. +
  3101. +#define SQUASHFS_COMPRESSED_BLOCK(B) (!((B) & SQUASHFS_COMPRESSED_BIT_BLOCK))
  3102. +
  3103. +/*
  3104. + * Inode number ops. Inodes consist of a compressed block number, and an
  3105. + * uncompressed offset within that block
  3106. + */
  3107. +#define SQUASHFS_INODE_BLK(a) ((unsigned int) ((a) >> 16))
  3108. +
  3109. +#define SQUASHFS_INODE_OFFSET(a) ((unsigned int) ((a) & 0xffff))
  3110. +
  3111. +#define SQUASHFS_MKINODE(A, B) ((squashfs_inode_t)(((squashfs_inode_t) (A)\
  3112. + << 16) + (B)))
  3113. +
  3114. +/* Compute 32 bit VFS inode number from squashfs inode number */
  3115. +#define SQUASHFS_MK_VFS_INODE(a, b) ((unsigned int) (((a) << 8) + \
  3116. + ((b) >> 2) + 1))
  3117. +/* XXX */
  3118. +
  3119. +/* Translate between VFS mode and squashfs mode */
  3120. +#define SQUASHFS_MODE(a) ((a) & 0xfff)
  3121. +
  3122. +/* fragment and fragment table defines */
  3123. +#define SQUASHFS_FRAGMENT_BYTES(A) (A * sizeof(struct squashfs_fragment_entry))
  3124. +
  3125. +#define SQUASHFS_FRAGMENT_INDEX(A) (SQUASHFS_FRAGMENT_BYTES(A) / \
  3126. + SQUASHFS_METADATA_SIZE)
  3127. +
  3128. +#define SQUASHFS_FRAGMENT_INDEX_OFFSET(A) (SQUASHFS_FRAGMENT_BYTES(A) % \
  3129. + SQUASHFS_METADATA_SIZE)
  3130. +
  3131. +#define SQUASHFS_FRAGMENT_INDEXES(A) ((SQUASHFS_FRAGMENT_BYTES(A) + \
  3132. + SQUASHFS_METADATA_SIZE - 1) / \
  3133. + SQUASHFS_METADATA_SIZE)
  3134. +
  3135. +#define SQUASHFS_FRAGMENT_INDEX_BYTES(A) (SQUASHFS_FRAGMENT_INDEXES(A) *\
  3136. + sizeof(long long))
  3137. +
  3138. +/* cached data constants for filesystem */
  3139. +#define SQUASHFS_CACHED_BLKS 8
  3140. +
  3141. +#define SQUASHFS_MAX_FILE_SIZE_LOG 64
  3142. +
  3143. +#define SQUASHFS_MAX_FILE_SIZE ((long long) 1 << \
  3144. + (SQUASHFS_MAX_FILE_SIZE_LOG - 2))
  3145. +
  3146. +#define SQUASHFS_MARKER_BYTE 0xff
  3147. +
  3148. +/* meta index cache */
  3149. +#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
  3150. +#define SQUASHFS_META_ENTRIES 31
  3151. +#define SQUASHFS_META_NUMBER 8
  3152. +#define SQUASHFS_SLOTS 4
  3153. +
  3154. +struct meta_entry {
  3155. + long long data_block;
  3156. + unsigned int index_block;
  3157. + unsigned short offset;
  3158. + unsigned short pad;
  3159. +};
  3160. +
  3161. +struct meta_index {
  3162. + unsigned int inode_number;
  3163. + unsigned int offset;
  3164. + unsigned short entries;
  3165. + unsigned short skip;
  3166. + unsigned short locked;
  3167. + unsigned short pad;
  3168. + struct meta_entry meta_entry[SQUASHFS_META_ENTRIES];
  3169. +};
  3170. +
  3171. +
  3172. +/*
  3173. + * definitions for structures on disk
  3174. + */
  3175. +
  3176. +typedef long long squashfs_block_t;
  3177. +typedef long long squashfs_inode_t;
  3178. +
  3179. +struct squashfs_super_block {
  3180. + unsigned int s_magic;
  3181. + unsigned int inodes;
  3182. + unsigned int bytes_used_2;
  3183. + unsigned int uid_start_2;
  3184. + unsigned int guid_start_2;
  3185. + unsigned int inode_table_start_2;
  3186. + unsigned int directory_table_start_2;
  3187. + unsigned int s_major:16;
  3188. + unsigned int s_minor:16;
  3189. + unsigned int block_size_1:16;
  3190. + unsigned int block_log:16;
  3191. + unsigned int flags:8;
  3192. + unsigned int no_uids:8;
  3193. + unsigned int no_guids:8;
  3194. + unsigned int mkfs_time /* time of filesystem creation */;
  3195. + squashfs_inode_t root_inode;
  3196. + unsigned int block_size;
  3197. + unsigned int fragments;
  3198. + unsigned int fragment_table_start_2;
  3199. + long long bytes_used;
  3200. + long long uid_start;
  3201. + long long guid_start;
  3202. + long long inode_table_start;
  3203. + long long directory_table_start;
  3204. + long long fragment_table_start;
  3205. + long long unused;
  3206. +} __attribute__ ((packed));
  3207. +
  3208. +struct squashfs_dir_index {
  3209. + unsigned int index;
  3210. + unsigned int start_block;
  3211. + unsigned char size;
  3212. + unsigned char name[0];
  3213. +} __attribute__ ((packed));
  3214. +
  3215. +#define SQUASHFS_BASE_INODE_HEADER \
  3216. + unsigned int inode_type:4; \
  3217. + unsigned int mode:12; \
  3218. + unsigned int uid:8; \
  3219. + unsigned int guid:8; \
  3220. + unsigned int mtime; \
  3221. + unsigned int inode_number;
  3222. +
  3223. +struct squashfs_base_inode_header {
  3224. + SQUASHFS_BASE_INODE_HEADER;
  3225. +} __attribute__ ((packed));
  3226. +
  3227. +struct squashfs_ipc_inode_header {
  3228. + SQUASHFS_BASE_INODE_HEADER;
  3229. + unsigned int nlink;
  3230. +} __attribute__ ((packed));
  3231. +
  3232. +struct squashfs_dev_inode_header {
  3233. + SQUASHFS_BASE_INODE_HEADER;
  3234. + unsigned int nlink;
  3235. + unsigned short rdev;
  3236. +} __attribute__ ((packed));
  3237. +
  3238. +struct squashfs_symlink_inode_header {
  3239. + SQUASHFS_BASE_INODE_HEADER;
  3240. + unsigned int nlink;
  3241. + unsigned short symlink_size;
  3242. + char symlink[0];
  3243. +} __attribute__ ((packed));
  3244. +
  3245. +struct squashfs_reg_inode_header {
  3246. + SQUASHFS_BASE_INODE_HEADER;
  3247. + squashfs_block_t start_block;
  3248. + unsigned int fragment;
  3249. + unsigned int offset;
  3250. + unsigned int file_size;
  3251. + unsigned short block_list[0];
  3252. +} __attribute__ ((packed));
  3253. +
  3254. +struct squashfs_lreg_inode_header {
  3255. + SQUASHFS_BASE_INODE_HEADER;
  3256. + unsigned int nlink;
  3257. + squashfs_block_t start_block;
  3258. + unsigned int fragment;
  3259. + unsigned int offset;
  3260. + long long file_size;
  3261. + unsigned short block_list[0];
  3262. +} __attribute__ ((packed));
  3263. +
  3264. +struct squashfs_dir_inode_header {
  3265. + SQUASHFS_BASE_INODE_HEADER;
  3266. + unsigned int nlink;
  3267. + unsigned int file_size:19;
  3268. + unsigned int offset:13;
  3269. + unsigned int start_block;
  3270. + unsigned int parent_inode;
  3271. +} __attribute__ ((packed));
  3272. +
  3273. +struct squashfs_ldir_inode_header {
  3274. + SQUASHFS_BASE_INODE_HEADER;
  3275. + unsigned int nlink;
  3276. + unsigned int file_size:27;
  3277. + unsigned int offset:13;
  3278. + unsigned int start_block;
  3279. + unsigned int i_count:16;
  3280. + unsigned int parent_inode;
  3281. + struct squashfs_dir_index index[0];
  3282. +} __attribute__ ((packed));
  3283. +
  3284. +union squashfs_inode_header {
  3285. + struct squashfs_base_inode_header base;
  3286. + struct squashfs_dev_inode_header dev;
  3287. + struct squashfs_symlink_inode_header symlink;
  3288. + struct squashfs_reg_inode_header reg;
  3289. + struct squashfs_lreg_inode_header lreg;
  3290. + struct squashfs_dir_inode_header dir;
  3291. + struct squashfs_ldir_inode_header ldir;
  3292. + struct squashfs_ipc_inode_header ipc;
  3293. +};
  3294. +
  3295. +struct squashfs_dir_entry {
  3296. + unsigned int offset:13;
  3297. + unsigned int type:3;
  3298. + unsigned int size:8;
  3299. + int inode_number:16;
  3300. + char name[0];
  3301. +} __attribute__ ((packed));
  3302. +
  3303. +struct squashfs_dir_header {
  3304. + unsigned int count:8;
  3305. + unsigned int start_block;
  3306. + unsigned int inode_number;
  3307. +} __attribute__ ((packed));
  3308. +
  3309. +struct squashfs_fragment_entry {
  3310. + long long start_block;
  3311. + unsigned int size;
  3312. + unsigned int unused;
  3313. +} __attribute__ ((packed));
  3314. +
  3315. +extern int squashfs_uncompress_block(void *d, int dstlen, void *s, int srclen);
  3316. +extern int squashfs_uncompress_init(void);
  3317. +extern int squashfs_uncompress_exit(void);
  3318. +
  3319. +/*
  3320. + * macros to convert each packed bitfield structure from little endian to big
  3321. + * endian and vice versa. These are needed when creating or using a filesystem
  3322. + * on a machine with different byte ordering to the target architecture.
  3323. + *
  3324. + */
  3325. +
  3326. +#define SQUASHFS_SWAP_START \
  3327. + int bits;\
  3328. + int b_pos;\
  3329. + unsigned long long val;\
  3330. + unsigned char *s;\
  3331. + unsigned char *d;
  3332. +
  3333. +#define SQUASHFS_SWAP_SUPER_BLOCK(s, d) {\
  3334. + SQUASHFS_SWAP_START\
  3335. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_super_block));\
  3336. + SQUASHFS_SWAP((s)->s_magic, d, 0, 32);\
  3337. + SQUASHFS_SWAP((s)->inodes, d, 32, 32);\
  3338. + SQUASHFS_SWAP((s)->bytes_used_2, d, 64, 32);\
  3339. + SQUASHFS_SWAP((s)->uid_start_2, d, 96, 32);\
  3340. + SQUASHFS_SWAP((s)->guid_start_2, d, 128, 32);\
  3341. + SQUASHFS_SWAP((s)->inode_table_start_2, d, 160, 32);\
  3342. + SQUASHFS_SWAP((s)->directory_table_start_2, d, 192, 32);\
  3343. + SQUASHFS_SWAP((s)->s_major, d, 224, 16);\
  3344. + SQUASHFS_SWAP((s)->s_minor, d, 240, 16);\
  3345. + SQUASHFS_SWAP((s)->block_size_1, d, 256, 16);\
  3346. + SQUASHFS_SWAP((s)->block_log, d, 272, 16);\
  3347. + SQUASHFS_SWAP((s)->flags, d, 288, 8);\
  3348. + SQUASHFS_SWAP((s)->no_uids, d, 296, 8);\
  3349. + SQUASHFS_SWAP((s)->no_guids, d, 304, 8);\
  3350. + SQUASHFS_SWAP((s)->mkfs_time, d, 312, 32);\
  3351. + SQUASHFS_SWAP((s)->root_inode, d, 344, 64);\
  3352. + SQUASHFS_SWAP((s)->block_size, d, 408, 32);\
  3353. + SQUASHFS_SWAP((s)->fragments, d, 440, 32);\
  3354. + SQUASHFS_SWAP((s)->fragment_table_start_2, d, 472, 32);\
  3355. + SQUASHFS_SWAP((s)->bytes_used, d, 504, 64);\
  3356. + SQUASHFS_SWAP((s)->uid_start, d, 568, 64);\
  3357. + SQUASHFS_SWAP((s)->guid_start, d, 632, 64);\
  3358. + SQUASHFS_SWAP((s)->inode_table_start, d, 696, 64);\
  3359. + SQUASHFS_SWAP((s)->directory_table_start, d, 760, 64);\
  3360. + SQUASHFS_SWAP((s)->fragment_table_start, d, 824, 64);\
  3361. + SQUASHFS_SWAP((s)->unused, d, 888, 64);\
  3362. +}
  3363. +
  3364. +#define SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
  3365. + SQUASHFS_MEMSET(s, d, n);\
  3366. + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
  3367. + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
  3368. + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
  3369. + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
  3370. + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
  3371. + SQUASHFS_SWAP((s)->inode_number, d, 64, 32);
  3372. +
  3373. +#define SQUASHFS_SWAP_BASE_INODE_HEADER(s, d, n) {\
  3374. + SQUASHFS_SWAP_START\
  3375. + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, n)\
  3376. +}
  3377. +
  3378. +#define SQUASHFS_SWAP_IPC_INODE_HEADER(s, d) {\
  3379. + SQUASHFS_SWAP_START\
  3380. + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
  3381. + sizeof(struct squashfs_ipc_inode_header))\
  3382. + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
  3383. +}
  3384. +
  3385. +#define SQUASHFS_SWAP_DEV_INODE_HEADER(s, d) {\
  3386. + SQUASHFS_SWAP_START\
  3387. + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
  3388. + sizeof(struct squashfs_dev_inode_header)); \
  3389. + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
  3390. + SQUASHFS_SWAP((s)->rdev, d, 128, 16);\
  3391. +}
  3392. +
  3393. +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER(s, d) {\
  3394. + SQUASHFS_SWAP_START\
  3395. + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
  3396. + sizeof(struct squashfs_symlink_inode_header));\
  3397. + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
  3398. + SQUASHFS_SWAP((s)->symlink_size, d, 128, 16);\
  3399. +}
  3400. +
  3401. +#define SQUASHFS_SWAP_REG_INODE_HEADER(s, d) {\
  3402. + SQUASHFS_SWAP_START\
  3403. + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
  3404. + sizeof(struct squashfs_reg_inode_header));\
  3405. + SQUASHFS_SWAP((s)->start_block, d, 96, 64);\
  3406. + SQUASHFS_SWAP((s)->fragment, d, 160, 32);\
  3407. + SQUASHFS_SWAP((s)->offset, d, 192, 32);\
  3408. + SQUASHFS_SWAP((s)->file_size, d, 224, 32);\
  3409. +}
  3410. +
  3411. +#define SQUASHFS_SWAP_LREG_INODE_HEADER(s, d) {\
  3412. + SQUASHFS_SWAP_START\
  3413. + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
  3414. + sizeof(struct squashfs_lreg_inode_header));\
  3415. + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
  3416. + SQUASHFS_SWAP((s)->start_block, d, 128, 64);\
  3417. + SQUASHFS_SWAP((s)->fragment, d, 192, 32);\
  3418. + SQUASHFS_SWAP((s)->offset, d, 224, 32);\
  3419. + SQUASHFS_SWAP((s)->file_size, d, 256, 64);\
  3420. +}
  3421. +
  3422. +#define SQUASHFS_SWAP_DIR_INODE_HEADER(s, d) {\
  3423. + SQUASHFS_SWAP_START\
  3424. + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
  3425. + sizeof(struct squashfs_dir_inode_header));\
  3426. + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
  3427. + SQUASHFS_SWAP((s)->file_size, d, 128, 19);\
  3428. + SQUASHFS_SWAP((s)->offset, d, 147, 13);\
  3429. + SQUASHFS_SWAP((s)->start_block, d, 160, 32);\
  3430. + SQUASHFS_SWAP((s)->parent_inode, d, 192, 32);\
  3431. +}
  3432. +
  3433. +#define SQUASHFS_SWAP_LDIR_INODE_HEADER(s, d) {\
  3434. + SQUASHFS_SWAP_START\
  3435. + SQUASHFS_SWAP_BASE_INODE_CORE(s, d, \
  3436. + sizeof(struct squashfs_ldir_inode_header));\
  3437. + SQUASHFS_SWAP((s)->nlink, d, 96, 32);\
  3438. + SQUASHFS_SWAP((s)->file_size, d, 128, 27);\
  3439. + SQUASHFS_SWAP((s)->offset, d, 155, 13);\
  3440. + SQUASHFS_SWAP((s)->start_block, d, 168, 32);\
  3441. + SQUASHFS_SWAP((s)->i_count, d, 200, 16);\
  3442. + SQUASHFS_SWAP((s)->parent_inode, d, 216, 32);\
  3443. +}
  3444. +
  3445. +#define SQUASHFS_SWAP_DIR_INDEX(s, d) {\
  3446. + SQUASHFS_SWAP_START\
  3447. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index));\
  3448. + SQUASHFS_SWAP((s)->index, d, 0, 32);\
  3449. + SQUASHFS_SWAP((s)->start_block, d, 32, 32);\
  3450. + SQUASHFS_SWAP((s)->size, d, 64, 8);\
  3451. +}
  3452. +
  3453. +#define SQUASHFS_SWAP_DIR_HEADER(s, d) {\
  3454. + SQUASHFS_SWAP_START\
  3455. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header));\
  3456. + SQUASHFS_SWAP((s)->count, d, 0, 8);\
  3457. + SQUASHFS_SWAP((s)->start_block, d, 8, 32);\
  3458. + SQUASHFS_SWAP((s)->inode_number, d, 40, 32);\
  3459. +}
  3460. +
  3461. +#define SQUASHFS_SWAP_DIR_ENTRY(s, d) {\
  3462. + SQUASHFS_SWAP_START\
  3463. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry));\
  3464. + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
  3465. + SQUASHFS_SWAP((s)->type, d, 13, 3);\
  3466. + SQUASHFS_SWAP((s)->size, d, 16, 8);\
  3467. + SQUASHFS_SWAP((s)->inode_number, d, 24, 16);\
  3468. +}
  3469. +
  3470. +#define SQUASHFS_SWAP_FRAGMENT_ENTRY(s, d) {\
  3471. + SQUASHFS_SWAP_START\
  3472. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry));\
  3473. + SQUASHFS_SWAP((s)->start_block, d, 0, 64);\
  3474. + SQUASHFS_SWAP((s)->size, d, 64, 32);\
  3475. +}
  3476. +
  3477. +#define SQUASHFS_SWAP_SHORTS(s, d, n) {\
  3478. + int entry;\
  3479. + int bit_position;\
  3480. + SQUASHFS_SWAP_START\
  3481. + SQUASHFS_MEMSET(s, d, n * 2);\
  3482. + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
  3483. + 16)\
  3484. + SQUASHFS_SWAP(s[entry], d, bit_position, 16);\
  3485. +}
  3486. +
  3487. +#define SQUASHFS_SWAP_INTS(s, d, n) {\
  3488. + int entry;\
  3489. + int bit_position;\
  3490. + SQUASHFS_SWAP_START\
  3491. + SQUASHFS_MEMSET(s, d, n * 4);\
  3492. + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
  3493. + 32)\
  3494. + SQUASHFS_SWAP(s[entry], d, bit_position, 32);\
  3495. +}
  3496. +
  3497. +#define SQUASHFS_SWAP_LONG_LONGS(s, d, n) {\
  3498. + int entry;\
  3499. + int bit_position;\
  3500. + SQUASHFS_SWAP_START\
  3501. + SQUASHFS_MEMSET(s, d, n * 8);\
  3502. + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
  3503. + 64)\
  3504. + SQUASHFS_SWAP(s[entry], d, bit_position, 64);\
  3505. +}
  3506. +
  3507. +#define SQUASHFS_SWAP_DATA(s, d, n, bits) {\
  3508. + int entry;\
  3509. + int bit_position;\
  3510. + SQUASHFS_SWAP_START\
  3511. + SQUASHFS_MEMSET(s, d, n * bits / 8);\
  3512. + for(entry = 0, bit_position = 0; entry < n; entry++, bit_position += \
  3513. + bits)\
  3514. + SQUASHFS_SWAP(s[entry], d, bit_position, bits);\
  3515. +}
  3516. +
  3517. +#define SQUASHFS_SWAP_FRAGMENT_INDEXES(s, d, n) SQUASHFS_SWAP_LONG_LONGS(s, d, n)
  3518. +
  3519. +#ifdef CONFIG_SQUASHFS_1_0_COMPATIBILITY
  3520. +
  3521. +struct squashfs_base_inode_header_1 {
  3522. + unsigned int inode_type:4;
  3523. + unsigned int mode:12; /* protection */
  3524. + unsigned int uid:4; /* index into uid table */
  3525. + unsigned int guid:4; /* index into guid table */
  3526. +} __attribute__ ((packed));
  3527. +
  3528. +struct squashfs_ipc_inode_header_1 {
  3529. + unsigned int inode_type:4;
  3530. + unsigned int mode:12; /* protection */
  3531. + unsigned int uid:4; /* index into uid table */
  3532. + unsigned int guid:4; /* index into guid table */
  3533. + unsigned int type:4;
  3534. + unsigned int offset:4;
  3535. +} __attribute__ ((packed));
  3536. +
  3537. +struct squashfs_dev_inode_header_1 {
  3538. + unsigned int inode_type:4;
  3539. + unsigned int mode:12; /* protection */
  3540. + unsigned int uid:4; /* index into uid table */
  3541. + unsigned int guid:4; /* index into guid table */
  3542. + unsigned short rdev;
  3543. +} __attribute__ ((packed));
  3544. +
  3545. +struct squashfs_symlink_inode_header_1 {
  3546. + unsigned int inode_type:4;
  3547. + unsigned int mode:12; /* protection */
  3548. + unsigned int uid:4; /* index into uid table */
  3549. + unsigned int guid:4; /* index into guid table */
  3550. + unsigned short symlink_size;
  3551. + char symlink[0];
  3552. +} __attribute__ ((packed));
  3553. +
  3554. +struct squashfs_reg_inode_header_1 {
  3555. + unsigned int inode_type:4;
  3556. + unsigned int mode:12; /* protection */
  3557. + unsigned int uid:4; /* index into uid table */
  3558. + unsigned int guid:4; /* index into guid table */
  3559. + unsigned int mtime;
  3560. + unsigned int start_block;
  3561. + unsigned int file_size:32;
  3562. + unsigned short block_list[0];
  3563. +} __attribute__ ((packed));
  3564. +
  3565. +struct squashfs_dir_inode_header_1 {
  3566. + unsigned int inode_type:4;
  3567. + unsigned int mode:12; /* protection */
  3568. + unsigned int uid:4; /* index into uid table */
  3569. + unsigned int guid:4; /* index into guid table */
  3570. + unsigned int file_size:19;
  3571. + unsigned int offset:13;
  3572. + unsigned int mtime;
  3573. + unsigned int start_block:24;
  3574. +} __attribute__ ((packed));
  3575. +
  3576. +#define SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n) \
  3577. + SQUASHFS_MEMSET(s, d, n);\
  3578. + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
  3579. + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
  3580. + SQUASHFS_SWAP((s)->uid, d, 16, 4);\
  3581. + SQUASHFS_SWAP((s)->guid, d, 20, 4);
  3582. +
  3583. +#define SQUASHFS_SWAP_BASE_INODE_HEADER_1(s, d, n) {\
  3584. + SQUASHFS_SWAP_START\
  3585. + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, n)\
  3586. +}
  3587. +
  3588. +#define SQUASHFS_SWAP_IPC_INODE_HEADER_1(s, d) {\
  3589. + SQUASHFS_SWAP_START\
  3590. + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
  3591. + sizeof(struct squashfs_ipc_inode_header_1));\
  3592. + SQUASHFS_SWAP((s)->type, d, 24, 4);\
  3593. + SQUASHFS_SWAP((s)->offset, d, 28, 4);\
  3594. +}
  3595. +
  3596. +#define SQUASHFS_SWAP_DEV_INODE_HEADER_1(s, d) {\
  3597. + SQUASHFS_SWAP_START\
  3598. + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
  3599. + sizeof(struct squashfs_dev_inode_header_1));\
  3600. + SQUASHFS_SWAP((s)->rdev, d, 24, 16);\
  3601. +}
  3602. +
  3603. +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_1(s, d) {\
  3604. + SQUASHFS_SWAP_START\
  3605. + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
  3606. + sizeof(struct squashfs_symlink_inode_header_1));\
  3607. + SQUASHFS_SWAP((s)->symlink_size, d, 24, 16);\
  3608. +}
  3609. +
  3610. +#define SQUASHFS_SWAP_REG_INODE_HEADER_1(s, d) {\
  3611. + SQUASHFS_SWAP_START\
  3612. + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
  3613. + sizeof(struct squashfs_reg_inode_header_1));\
  3614. + SQUASHFS_SWAP((s)->mtime, d, 24, 32);\
  3615. + SQUASHFS_SWAP((s)->start_block, d, 56, 32);\
  3616. + SQUASHFS_SWAP((s)->file_size, d, 88, 32);\
  3617. +}
  3618. +
  3619. +#define SQUASHFS_SWAP_DIR_INODE_HEADER_1(s, d) {\
  3620. + SQUASHFS_SWAP_START\
  3621. + SQUASHFS_SWAP_BASE_INODE_CORE_1(s, d, \
  3622. + sizeof(struct squashfs_dir_inode_header_1));\
  3623. + SQUASHFS_SWAP((s)->file_size, d, 24, 19);\
  3624. + SQUASHFS_SWAP((s)->offset, d, 43, 13);\
  3625. + SQUASHFS_SWAP((s)->mtime, d, 56, 32);\
  3626. + SQUASHFS_SWAP((s)->start_block, d, 88, 24);\
  3627. +}
  3628. +
  3629. +#endif
  3630. +
  3631. +#ifdef CONFIG_SQUASHFS_2_0_COMPATIBILITY
  3632. +
  3633. +struct squashfs_dir_index_2 {
  3634. + unsigned int index:27;
  3635. + unsigned int start_block:29;
  3636. + unsigned char size;
  3637. + unsigned char name[0];
  3638. +} __attribute__ ((packed));
  3639. +
  3640. +struct squashfs_base_inode_header_2 {
  3641. + unsigned int inode_type:4;
  3642. + unsigned int mode:12; /* protection */
  3643. + unsigned int uid:8; /* index into uid table */
  3644. + unsigned int guid:8; /* index into guid table */
  3645. +} __attribute__ ((packed));
  3646. +
  3647. +struct squashfs_ipc_inode_header_2 {
  3648. + unsigned int inode_type:4;
  3649. + unsigned int mode:12; /* protection */
  3650. + unsigned int uid:8; /* index into uid table */
  3651. + unsigned int guid:8; /* index into guid table */
  3652. +} __attribute__ ((packed));
  3653. +
  3654. +struct squashfs_dev_inode_header_2 {
  3655. + unsigned int inode_type:4;
  3656. + unsigned int mode:12; /* protection */
  3657. + unsigned int uid:8; /* index into uid table */
  3658. + unsigned int guid:8; /* index into guid table */
  3659. + unsigned short rdev;
  3660. +} __attribute__ ((packed));
  3661. +
  3662. +struct squashfs_symlink_inode_header_2 {
  3663. + unsigned int inode_type:4;
  3664. + unsigned int mode:12; /* protection */
  3665. + unsigned int uid:8; /* index into uid table */
  3666. + unsigned int guid:8; /* index into guid table */
  3667. + unsigned short symlink_size;
  3668. + char symlink[0];
  3669. +} __attribute__ ((packed));
  3670. +
  3671. +struct squashfs_reg_inode_header_2 {
  3672. + unsigned int inode_type:4;
  3673. + unsigned int mode:12; /* protection */
  3674. + unsigned int uid:8; /* index into uid table */
  3675. + unsigned int guid:8; /* index into guid table */
  3676. + unsigned int mtime;
  3677. + unsigned int start_block;
  3678. + unsigned int fragment;
  3679. + unsigned int offset;
  3680. + unsigned int file_size:32;
  3681. + unsigned short block_list[0];
  3682. +} __attribute__ ((packed));
  3683. +
  3684. +struct squashfs_dir_inode_header_2 {
  3685. + unsigned int inode_type:4;
  3686. + unsigned int mode:12; /* protection */
  3687. + unsigned int uid:8; /* index into uid table */
  3688. + unsigned int guid:8; /* index into guid table */
  3689. + unsigned int file_size:19;
  3690. + unsigned int offset:13;
  3691. + unsigned int mtime;
  3692. + unsigned int start_block:24;
  3693. +} __attribute__ ((packed));
  3694. +
  3695. +struct squashfs_ldir_inode_header_2 {
  3696. + unsigned int inode_type:4;
  3697. + unsigned int mode:12; /* protection */
  3698. + unsigned int uid:8; /* index into uid table */
  3699. + unsigned int guid:8; /* index into guid table */
  3700. + unsigned int file_size:27;
  3701. + unsigned int offset:13;
  3702. + unsigned int mtime;
  3703. + unsigned int start_block:24;
  3704. + unsigned int i_count:16;
  3705. + struct squashfs_dir_index_2 index[0];
  3706. +} __attribute__ ((packed));
  3707. +
  3708. +union squashfs_inode_header_2 {
  3709. + struct squashfs_base_inode_header_2 base;
  3710. + struct squashfs_dev_inode_header_2 dev;
  3711. + struct squashfs_symlink_inode_header_2 symlink;
  3712. + struct squashfs_reg_inode_header_2 reg;
  3713. + struct squashfs_dir_inode_header_2 dir;
  3714. + struct squashfs_ldir_inode_header_2 ldir;
  3715. + struct squashfs_ipc_inode_header_2 ipc;
  3716. +};
  3717. +
  3718. +struct squashfs_dir_header_2 {
  3719. + unsigned int count:8;
  3720. + unsigned int start_block:24;
  3721. +} __attribute__ ((packed));
  3722. +
  3723. +struct squashfs_dir_entry_2 {
  3724. + unsigned int offset:13;
  3725. + unsigned int type:3;
  3726. + unsigned int size:8;
  3727. + char name[0];
  3728. +} __attribute__ ((packed));
  3729. +
  3730. +struct squashfs_fragment_entry_2 {
  3731. + unsigned int start_block;
  3732. + unsigned int size;
  3733. +} __attribute__ ((packed));
  3734. +
  3735. +#define SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
  3736. + SQUASHFS_MEMSET(s, d, n);\
  3737. + SQUASHFS_SWAP((s)->inode_type, d, 0, 4);\
  3738. + SQUASHFS_SWAP((s)->mode, d, 4, 12);\
  3739. + SQUASHFS_SWAP((s)->uid, d, 16, 8);\
  3740. + SQUASHFS_SWAP((s)->guid, d, 24, 8);\
  3741. +
  3742. +#define SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, n) {\
  3743. + SQUASHFS_SWAP_START\
  3744. + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, n)\
  3745. +}
  3746. +
  3747. +#define SQUASHFS_SWAP_IPC_INODE_HEADER_2(s, d) \
  3748. + SQUASHFS_SWAP_BASE_INODE_HEADER_2(s, d, sizeof(struct squashfs_ipc_inode_header_2))
  3749. +
  3750. +#define SQUASHFS_SWAP_DEV_INODE_HEADER_2(s, d) {\
  3751. + SQUASHFS_SWAP_START\
  3752. + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
  3753. + sizeof(struct squashfs_dev_inode_header_2)); \
  3754. + SQUASHFS_SWAP((s)->rdev, d, 32, 16);\
  3755. +}
  3756. +
  3757. +#define SQUASHFS_SWAP_SYMLINK_INODE_HEADER_2(s, d) {\
  3758. + SQUASHFS_SWAP_START\
  3759. + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
  3760. + sizeof(struct squashfs_symlink_inode_header_2));\
  3761. + SQUASHFS_SWAP((s)->symlink_size, d, 32, 16);\
  3762. +}
  3763. +
  3764. +#define SQUASHFS_SWAP_REG_INODE_HEADER_2(s, d) {\
  3765. + SQUASHFS_SWAP_START\
  3766. + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
  3767. + sizeof(struct squashfs_reg_inode_header_2));\
  3768. + SQUASHFS_SWAP((s)->mtime, d, 32, 32);\
  3769. + SQUASHFS_SWAP((s)->start_block, d, 64, 32);\
  3770. + SQUASHFS_SWAP((s)->fragment, d, 96, 32);\
  3771. + SQUASHFS_SWAP((s)->offset, d, 128, 32);\
  3772. + SQUASHFS_SWAP((s)->file_size, d, 160, 32);\
  3773. +}
  3774. +
  3775. +#define SQUASHFS_SWAP_DIR_INODE_HEADER_2(s, d) {\
  3776. + SQUASHFS_SWAP_START\
  3777. + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
  3778. + sizeof(struct squashfs_dir_inode_header_2));\
  3779. + SQUASHFS_SWAP((s)->file_size, d, 32, 19);\
  3780. + SQUASHFS_SWAP((s)->offset, d, 51, 13);\
  3781. + SQUASHFS_SWAP((s)->mtime, d, 64, 32);\
  3782. + SQUASHFS_SWAP((s)->start_block, d, 96, 24);\
  3783. +}
  3784. +
  3785. +#define SQUASHFS_SWAP_LDIR_INODE_HEADER_2(s, d) {\
  3786. + SQUASHFS_SWAP_START\
  3787. + SQUASHFS_SWAP_BASE_INODE_CORE_2(s, d, \
  3788. + sizeof(struct squashfs_ldir_inode_header_2));\
  3789. + SQUASHFS_SWAP((s)->file_size, d, 32, 27);\
  3790. + SQUASHFS_SWAP((s)->offset, d, 59, 13);\
  3791. + SQUASHFS_SWAP((s)->mtime, d, 72, 32);\
  3792. + SQUASHFS_SWAP((s)->start_block, d, 104, 24);\
  3793. + SQUASHFS_SWAP((s)->i_count, d, 128, 16);\
  3794. +}
  3795. +
  3796. +#define SQUASHFS_SWAP_DIR_INDEX_2(s, d) {\
  3797. + SQUASHFS_SWAP_START\
  3798. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_index_2));\
  3799. + SQUASHFS_SWAP((s)->index, d, 0, 27);\
  3800. + SQUASHFS_SWAP((s)->start_block, d, 27, 29);\
  3801. + SQUASHFS_SWAP((s)->size, d, 56, 8);\
  3802. +}
  3803. +#define SQUASHFS_SWAP_DIR_HEADER_2(s, d) {\
  3804. + SQUASHFS_SWAP_START\
  3805. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_header_2));\
  3806. + SQUASHFS_SWAP((s)->count, d, 0, 8);\
  3807. + SQUASHFS_SWAP((s)->start_block, d, 8, 24);\
  3808. +}
  3809. +
  3810. +#define SQUASHFS_SWAP_DIR_ENTRY_2(s, d) {\
  3811. + SQUASHFS_SWAP_START\
  3812. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_dir_entry_2));\
  3813. + SQUASHFS_SWAP((s)->offset, d, 0, 13);\
  3814. + SQUASHFS_SWAP((s)->type, d, 13, 3);\
  3815. + SQUASHFS_SWAP((s)->size, d, 16, 8);\
  3816. +}
  3817. +
  3818. +#define SQUASHFS_SWAP_FRAGMENT_ENTRY_2(s, d) {\
  3819. + SQUASHFS_SWAP_START\
  3820. + SQUASHFS_MEMSET(s, d, sizeof(struct squashfs_fragment_entry_2));\
  3821. + SQUASHFS_SWAP((s)->start_block, d, 0, 32);\
  3822. + SQUASHFS_SWAP((s)->size, d, 32, 32);\
  3823. +}
  3824. +
  3825. +#define SQUASHFS_SWAP_FRAGMENT_INDEXES_2(s, d, n) SQUASHFS_SWAP_INTS(s, d, n)
  3826. +
  3827. +/* fragment and fragment table defines */
  3828. +#define SQUASHFS_FRAGMENT_BYTES_2(A) (A * sizeof(struct squashfs_fragment_entry_2))
  3829. +
  3830. +#define SQUASHFS_FRAGMENT_INDEX_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) / \
  3831. + SQUASHFS_METADATA_SIZE)
  3832. +
  3833. +#define SQUASHFS_FRAGMENT_INDEX_OFFSET_2(A) (SQUASHFS_FRAGMENT_BYTES_2(A) % \
  3834. + SQUASHFS_METADATA_SIZE)
  3835. +
  3836. +#define SQUASHFS_FRAGMENT_INDEXES_2(A) ((SQUASHFS_FRAGMENT_BYTES_2(A) + \
  3837. + SQUASHFS_METADATA_SIZE - 1) / \
  3838. + SQUASHFS_METADATA_SIZE)
  3839. +
  3840. +#define SQUASHFS_FRAGMENT_INDEX_BYTES_2(A) (SQUASHFS_FRAGMENT_INDEXES_2(A) *\
  3841. + sizeof(int))
  3842. +
  3843. +#endif
  3844. +
  3845. +#ifdef __KERNEL__
  3846. +
  3847. +/*
  3848. + * macros used to swap each structure entry, taking into account
  3849. + * bitfields and different bitfield placing conventions on differing
  3850. + * architectures
  3851. + */
  3852. +
  3853. +#include <asm/byteorder.h>
  3854. +
  3855. +#ifdef __BIG_ENDIAN
  3856. + /* convert from little endian to big endian */
  3857. +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
  3858. + tbits, b_pos)
  3859. +#else
  3860. + /* convert from big endian to little endian */
  3861. +#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, \
  3862. + tbits, 64 - tbits - b_pos)
  3863. +#endif
  3864. +
  3865. +#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
  3866. + b_pos = pos % 8;\
  3867. + val = 0;\
  3868. + s = (unsigned char *)p + (pos / 8);\
  3869. + d = ((unsigned char *) &val) + 7;\
  3870. + for(bits = 0; bits < (tbits + b_pos); bits += 8) \
  3871. + *d-- = *s++;\
  3872. + value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
  3873. +}
  3874. +
  3875. +#define SQUASHFS_MEMSET(s, d, n) memset(s, 0, n);
  3876. +
  3877. +#endif
  3878. +#endif
  3879. Index: linux-2.4.35.4/include/linux/squashfs_fs_i.h
  3880. ===================================================================
  3881. --- /dev/null
  3882. +++ linux-2.4.35.4/include/linux/squashfs_fs_i.h
  3883. @@ -0,0 +1,44 @@
  3884. +#ifndef SQUASHFS_FS_I
  3885. +#define SQUASHFS_FS_I
  3886. +/*
  3887. + * Squashfs
  3888. + *
  3889. + * Copyright (c) 2002, 2003, 2004, 2005, 2006
  3890. + * Phillip Lougher <[email protected]>
  3891. + *
  3892. + * This program is free software; you can redistribute it and/or
  3893. + * modify it under the terms of the GNU General Public License
  3894. + * as published by the Free Software Foundation; either version 2,
  3895. + * or (at your option) any later version.
  3896. + *
  3897. + * This program is distributed in the hope that it will be useful,
  3898. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3899. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3900. + * GNU General Public License for more details.
  3901. + *
  3902. + * You should have received a copy of the GNU General Public License
  3903. + * along with this program; if not, write to the Free Software
  3904. + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  3905. + *
  3906. + * squashfs_fs_i.h
  3907. + */
  3908. +
  3909. +struct squashfs_inode_info {
  3910. + long long start_block;
  3911. + unsigned int offset;
  3912. + union {
  3913. + struct {
  3914. + long long fragment_start_block;
  3915. + unsigned int fragment_size;
  3916. + unsigned int fragment_offset;
  3917. + long long block_list_start;
  3918. + } s1;
  3919. + struct {
  3920. + long long directory_index_start;
  3921. + unsigned int directory_index_offset;
  3922. + unsigned int directory_index_count;
  3923. + unsigned int parent_inode;
  3924. + } s2;
  3925. + } u;
  3926. +};
  3927. +#endif
  3928. Index: linux-2.4.35.4/include/linux/squashfs_fs_sb.h
  3929. ===================================================================
  3930. --- /dev/null
  3931. +++ linux-2.4.35.4/include/linux/squashfs_fs_sb.h
  3932. @@ -0,0 +1,74 @@
  3933. +#ifndef SQUASHFS_FS_SB
  3934. +#define SQUASHFS_FS_SB
  3935. +/*
  3936. + * Squashfs
  3937. + *
  3938. + * Copyright (c) 2002, 2003, 2004, 2005, 2006
  3939. + * Phillip Lougher <[email protected]>
  3940. + *
  3941. + * This program is free software; you can redistribute it and/or
  3942. + * modify it under the terms of the GNU General Public License
  3943. + * as published by the Free Software Foundation; either version 2,
  3944. + * or (at your option) any later version.
  3945. + *
  3946. + * This program is distributed in the hope that it will be useful,
  3947. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3948. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3949. + * GNU General Public License for more details.
  3950. + *
  3951. + * You should have received a copy of the GNU General Public License
  3952. + * along with this program; if not, write to the Free Software
  3953. + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  3954. + *
  3955. + * squashfs_fs_sb.h
  3956. + */
  3957. +
  3958. +#include <linux/squashfs_fs.h>
  3959. +
  3960. +struct squashfs_cache {
  3961. + long long block;
  3962. + int length;
  3963. + long long next_index;
  3964. + char *data;
  3965. +};
  3966. +
  3967. +struct squashfs_fragment_cache {
  3968. + long long block;
  3969. + int length;
  3970. + unsigned int locked;
  3971. + char *data;
  3972. +};
  3973. +
  3974. +struct squashfs_sb_info {
  3975. + struct squashfs_super_block sblk;
  3976. + int devblksize;
  3977. + int devblksize_log2;
  3978. + int swap;
  3979. + struct squashfs_cache *block_cache;
  3980. + struct squashfs_fragment_cache *fragment;
  3981. + int next_cache;
  3982. + int next_fragment;
  3983. + int next_meta_index;
  3984. + unsigned int *uid;
  3985. + unsigned int *guid;
  3986. + long long *fragment_index;
  3987. + unsigned int *fragment_index_2;
  3988. + unsigned int read_size;
  3989. + char *read_data;
  3990. + char *read_page;
  3991. + struct semaphore read_data_mutex;
  3992. + struct semaphore read_page_mutex;
  3993. + struct semaphore block_cache_mutex;
  3994. + struct semaphore fragment_mutex;
  3995. + struct semaphore meta_index_mutex;
  3996. + wait_queue_head_t waitq;
  3997. + wait_queue_head_t fragment_wait_queue;
  3998. + struct meta_index *meta_index;
  3999. + struct inode *(*iget)(struct super_block *s, squashfs_inode_t \
  4000. + inode);
  4001. + long long (*read_blocklist)(struct inode *inode, int \
  4002. + index, int readahead_blks, char *block_list, \
  4003. + unsigned short **block_p, unsigned int *bsize);
  4004. + int (*read_fragment_index_table)(struct super_block *s);
  4005. +};
  4006. +#endif
  4007. Index: linux-2.4.35.4/init/do_mounts.c
  4008. ===================================================================
  4009. --- linux-2.4.35.4.orig/init/do_mounts.c
  4010. +++ linux-2.4.35.4/init/do_mounts.c
  4011. @@ -15,6 +15,7 @@
  4012. #include <linux/minix_fs.h>
  4013. #include <linux/ext2_fs.h>
  4014. #include <linux/romfs_fs.h>
  4015. +#include <linux/squashfs_fs.h>
  4016. #include <linux/cramfs_fs.h>
  4017. #define BUILD_CRAMDISK
  4018. @@ -476,6 +477,7 @@ static int __init crd_load(int in_fd, in
  4019. * minix
  4020. * ext2
  4021. * romfs
  4022. + * squashfs
  4023. * cramfs
  4024. * gzip
  4025. */
  4026. @@ -486,6 +488,7 @@ identify_ramdisk_image(int fd, int start
  4027. struct minix_super_block *minixsb;
  4028. struct ext2_super_block *ext2sb;
  4029. struct romfs_super_block *romfsb;
  4030. + struct squashfs_super_block *squashfsb;
  4031. struct cramfs_super *cramfsb;
  4032. int nblocks = -1;
  4033. unsigned char *buf;
  4034. @@ -497,6 +500,7 @@ identify_ramdisk_image(int fd, int start
  4035. minixsb = (struct minix_super_block *) buf;
  4036. ext2sb = (struct ext2_super_block *) buf;
  4037. romfsb = (struct romfs_super_block *) buf;
  4038. + squashfsb = (struct squashfs_super_block *) buf;
  4039. cramfsb = (struct cramfs_super *) buf;
  4040. memset(buf, 0xe5, size);
  4041. @@ -535,6 +539,15 @@ identify_ramdisk_image(int fd, int start
  4042. goto done;
  4043. }
  4044. + /* squashfs is at block zero too */
  4045. + if (squashfsb->s_magic == SQUASHFS_MAGIC) {
  4046. + printk(KERN_NOTICE
  4047. + "RAMDISK: squashfs filesystem found at block %d\n",
  4048. + start_block);
  4049. + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS;
  4050. + goto done;
  4051. + }
  4052. +
  4053. /*
  4054. * Read block 1 to test for minix and ext2 superblock
  4055. */
  4056. Index: linux-2.4.35.4/lib/Config.in
  4057. ===================================================================
  4058. --- linux-2.4.35.4.orig/lib/Config.in
  4059. +++ linux-2.4.35.4/lib/Config.in
  4060. @@ -10,6 +10,7 @@ tristate 'CRC32 functions' CONFIG_CRC32
  4061. # Do we need the compression support?
  4062. #
  4063. if [ "$CONFIG_CRAMFS" = "y" -o \
  4064. + "$CONFIG_SQUASHFS" = "y" -o \
  4065. "$CONFIG_PPP_DEFLATE" = "y" -o \
  4066. "$CONFIG_CRYPTO_DEFLATE" = "y" -o \
  4067. "$CONFIG_JFFS2_FS" = "y" -o \
  4068. @@ -17,6 +18,7 @@ if [ "$CONFIG_CRAMFS" = "y" -o \
  4069. define_tristate CONFIG_ZLIB_INFLATE y
  4070. else
  4071. if [ "$CONFIG_CRAMFS" = "m" -o \
  4072. + "$CONFIG_SQUASHFS" = "m" -o \
  4073. "$CONFIG_PPP_DEFLATE" = "m" -o \
  4074. "$CONFIG_CRYPTO_DEFLATE" = "m" -o \
  4075. "$CONFIG_JFFS2_FS" = "m" -o \