jffs2_1pass.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878
  1. /*
  2. -------------------------------------------------------------------------
  3. * Filename: jffs2.c
  4. * Version: $Id: jffs2_1pass.c,v 1.7 2002/01/25 01:56:47 nyet Exp $
  5. * Copyright: Copyright (C) 2001, Russ Dill
  6. * Author: Russ Dill <Russ.Dill@asu.edu>
  7. * Description: Module to load kernel from jffs2
  8. *-----------------------------------------------------------------------*/
  9. /*
  10. * some portions of this code are taken from jffs2, and as such, the
  11. * following copyright notice is included.
  12. *
  13. * JFFS2 -- Journalling Flash File System, Version 2.
  14. *
  15. * Copyright (C) 2001 Red Hat, Inc.
  16. *
  17. * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
  18. *
  19. * The original JFFS, from which the design for JFFS2 was derived,
  20. * was designed and implemented by Axis Communications AB.
  21. *
  22. * The contents of this file are subject to the Red Hat eCos Public
  23. * License Version 1.1 (the "Licence"); you may not use this file
  24. * except in compliance with the Licence. You may obtain a copy of
  25. * the Licence at http://www.redhat.com/
  26. *
  27. * Software distributed under the Licence is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  29. * See the Licence for the specific language governing rights and
  30. * limitations under the Licence.
  31. *
  32. * The Original Code is JFFS2 - Journalling Flash File System, version 2
  33. *
  34. * Alternatively, the contents of this file may be used under the
  35. * terms of the GNU General Public License version 2 (the "GPL"), in
  36. * which case the provisions of the GPL are applicable instead of the
  37. * above. If you wish to allow the use of your version of this file
  38. * only under the terms of the GPL and not to allow others to use your
  39. * version of this file under the RHEPL, indicate your decision by
  40. * deleting the provisions above and replace them with the notice and
  41. * other provisions required by the GPL. If you do not delete the
  42. * provisions above, a recipient may use your version of this file
  43. * under either the RHEPL or the GPL.
  44. *
  45. * $Id: jffs2_1pass.c,v 1.7 2002/01/25 01:56:47 nyet Exp $
  46. *
  47. */
  48. /* Ok, so anyone who knows the jffs2 code will probably want to get a papar
  49. * bag to throw up into before reading this code. I looked through the jffs2
  50. * code, the caching scheme is very elegant. I tried to keep the version
  51. * for a bootloader as small and simple as possible. Instead of worring about
  52. * unneccesary data copies, node scans, etc, I just optimized for the known
  53. * common case, a kernel, which looks like:
  54. * (1) most pages are 4096 bytes
  55. * (2) version numbers are somewhat sorted in acsending order
  56. * (3) multiple compressed blocks making up one page is uncommon
  57. *
  58. * So I create a linked list of decending version numbers (insertions at the
  59. * head), and then for each page, walk down the list, until a matching page
  60. * with 4096 bytes is found, and then decompress the watching pages in
  61. * reverse order.
  62. *
  63. */
  64. /*
  65. * Adapted by Nye Liu <nyet@zumanetworks.com> and
  66. * Rex Feany <rfeany@zumanetworks.com>
  67. * on Jan/2002 for U-Boot.
  68. *
  69. * Clipped out all the non-1pass functions, cleaned up warnings,
  70. * wrappers, etc. No major changes to the code.
  71. * Please, he really means it when he said have a paper bag
  72. * handy. We needed it ;).
  73. *
  74. */
  75. /*
  76. * Bugfixing by Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>, (C) Mar/2003
  77. *
  78. * - overhaul of the memory management. Removed much of the "paper-bagging"
  79. * in that part of the code, fixed several bugs, now frees memory when
  80. * partition is changed.
  81. * It's still ugly :-(
  82. * - fixed a bug in jffs2_1pass_read_inode where the file length calculation
  83. * was incorrect. Removed a bit of the paper-bagging as well.
  84. * - removed double crc calculation for fragment headers in jffs2_private.h
  85. * for speedup.
  86. * - scan_empty rewritten in a more "standard" manner (non-paperbag, that is).
  87. * - spinning wheel now spins depending on how much memory has been scanned
  88. * - lots of small changes all over the place to "improve" readability.
  89. * - implemented fragment sorting to ensure that the newest data is copied
  90. * if there are multiple copies of fragments for a certain file offset.
  91. *
  92. * The fragment sorting feature must be enabled by CONFIG_SYS_JFFS2_SORT_FRAGMENTS.
  93. * Sorting is done while adding fragments to the lists, which is more or less a
  94. * bubble sort. This takes a lot of time, and is most probably not an issue if
  95. * the boot filesystem is always mounted readonly.
  96. *
  97. * You should define it if the boot filesystem is mounted writable, and updates
  98. * to the boot files are done by copying files to that filesystem.
  99. *
  100. *
  101. * There's a big issue left: endianess is completely ignored in this code. Duh!
  102. *
  103. *
  104. * You still should have paper bags at hand :-(. The code lacks more or less
  105. * any comment, and is still arcane and difficult to read in places. As this
  106. * might be incompatible with any new code from the jffs2 maintainers anyway,
  107. * it should probably be dumped and replaced by something like jffs2reader!
  108. */
  109. #include <common.h>
  110. #include <config.h>
  111. #include <malloc.h>
  112. #include <div64.h>
  113. #include <linux/stat.h>
  114. #include <linux/time.h>
  115. #include <watchdog.h>
  116. #include <jffs2/jffs2.h>
  117. #include <jffs2/jffs2_1pass.h>
  118. #include <linux/compat.h>
  119. #include <asm/errno.h>
  120. #include "jffs2_private.h"
  121. #define NODE_CHUNK 1024 /* size of memory allocation chunk in b_nodes */
  122. #define SPIN_BLKSIZE 18 /* spin after having scanned 1<<BLKSIZE bytes */
  123. /* Debugging switches */
  124. #undef DEBUG_DIRENTS /* print directory entry list after scan */
  125. #undef DEBUG_FRAGMENTS /* print fragment list after scan */
  126. #undef DEBUG /* enable debugging messages */
  127. #ifdef DEBUG
  128. # define DEBUGF(fmt,args...) printf(fmt ,##args)
  129. #else
  130. # define DEBUGF(fmt,args...)
  131. #endif
  132. #include "summary.h"
  133. /* keeps pointer to currentlu processed partition */
  134. static struct part_info *current_part;
  135. #if (defined(CONFIG_JFFS2_NAND) && \
  136. defined(CONFIG_CMD_NAND) )
  137. #include <nand.h>
  138. /*
  139. * Support for jffs2 on top of NAND-flash
  140. *
  141. * NAND memory isn't mapped in processor's address space,
  142. * so data should be fetched from flash before
  143. * being processed. This is exactly what functions declared
  144. * here do.
  145. *
  146. */
  147. #define NAND_PAGE_SIZE 512
  148. #define NAND_PAGE_SHIFT 9
  149. #define NAND_PAGE_MASK (~(NAND_PAGE_SIZE-1))
  150. #ifndef NAND_CACHE_PAGES
  151. #define NAND_CACHE_PAGES 16
  152. #endif
  153. #define NAND_CACHE_SIZE (NAND_CACHE_PAGES*NAND_PAGE_SIZE)
  154. static u8* nand_cache = NULL;
  155. static u32 nand_cache_off = (u32)-1;
  156. static int read_nand_cached(u32 off, u32 size, u_char *buf)
  157. {
  158. struct mtdids *id = current_part->dev->id;
  159. u32 bytes_read = 0;
  160. size_t retlen;
  161. int cpy_bytes;
  162. while (bytes_read < size) {
  163. if ((off + bytes_read < nand_cache_off) ||
  164. (off + bytes_read >= nand_cache_off+NAND_CACHE_SIZE)) {
  165. nand_cache_off = (off + bytes_read) & NAND_PAGE_MASK;
  166. if (!nand_cache) {
  167. /* This memory never gets freed but 'cause
  168. it's a bootloader, nobody cares */
  169. nand_cache = malloc(NAND_CACHE_SIZE);
  170. if (!nand_cache) {
  171. printf("read_nand_cached: can't alloc cache size %d bytes\n",
  172. NAND_CACHE_SIZE);
  173. return -1;
  174. }
  175. }
  176. retlen = NAND_CACHE_SIZE;
  177. if (nand_read(&nand_info[id->num], nand_cache_off,
  178. &retlen, nand_cache) != 0 ||
  179. retlen != NAND_CACHE_SIZE) {
  180. printf("read_nand_cached: error reading nand off %#x size %d bytes\n",
  181. nand_cache_off, NAND_CACHE_SIZE);
  182. return -1;
  183. }
  184. }
  185. cpy_bytes = nand_cache_off + NAND_CACHE_SIZE - (off + bytes_read);
  186. if (cpy_bytes > size - bytes_read)
  187. cpy_bytes = size - bytes_read;
  188. memcpy(buf + bytes_read,
  189. nand_cache + off + bytes_read - nand_cache_off,
  190. cpy_bytes);
  191. bytes_read += cpy_bytes;
  192. }
  193. return bytes_read;
  194. }
  195. static void *get_fl_mem_nand(u32 off, u32 size, void *ext_buf)
  196. {
  197. u_char *buf = ext_buf ? (u_char*)ext_buf : (u_char*)malloc(size);
  198. if (NULL == buf) {
  199. printf("get_fl_mem_nand: can't alloc %d bytes\n", size);
  200. return NULL;
  201. }
  202. if (read_nand_cached(off, size, buf) < 0) {
  203. if (!ext_buf)
  204. free(buf);
  205. return NULL;
  206. }
  207. return buf;
  208. }
  209. static void *get_node_mem_nand(u32 off, void *ext_buf)
  210. {
  211. struct jffs2_unknown_node node;
  212. void *ret = NULL;
  213. if (NULL == get_fl_mem_nand(off, sizeof(node), &node))
  214. return NULL;
  215. if (!(ret = get_fl_mem_nand(off, node.magic ==
  216. JFFS2_MAGIC_BITMASK ? node.totlen : sizeof(node),
  217. ext_buf))) {
  218. printf("off = %#x magic %#x type %#x node.totlen = %d\n",
  219. off, node.magic, node.nodetype, node.totlen);
  220. }
  221. return ret;
  222. }
  223. static void put_fl_mem_nand(void *buf)
  224. {
  225. free(buf);
  226. }
  227. #endif
  228. #if defined(CONFIG_CMD_ONENAND)
  229. #include <linux/mtd/mtd.h>
  230. #include <linux/mtd/onenand.h>
  231. #include <onenand_uboot.h>
  232. #define ONENAND_PAGE_SIZE 2048
  233. #define ONENAND_PAGE_SHIFT 11
  234. #define ONENAND_PAGE_MASK (~(ONENAND_PAGE_SIZE-1))
  235. #ifndef ONENAND_CACHE_PAGES
  236. #define ONENAND_CACHE_PAGES 4
  237. #endif
  238. #define ONENAND_CACHE_SIZE (ONENAND_CACHE_PAGES*ONENAND_PAGE_SIZE)
  239. static u8* onenand_cache;
  240. static u32 onenand_cache_off = (u32)-1;
  241. static int read_onenand_cached(u32 off, u32 size, u_char *buf)
  242. {
  243. u32 bytes_read = 0;
  244. size_t retlen;
  245. int cpy_bytes;
  246. while (bytes_read < size) {
  247. if ((off + bytes_read < onenand_cache_off) ||
  248. (off + bytes_read >= onenand_cache_off + ONENAND_CACHE_SIZE)) {
  249. onenand_cache_off = (off + bytes_read) & ONENAND_PAGE_MASK;
  250. if (!onenand_cache) {
  251. /* This memory never gets freed but 'cause
  252. it's a bootloader, nobody cares */
  253. onenand_cache = malloc(ONENAND_CACHE_SIZE);
  254. if (!onenand_cache) {
  255. printf("read_onenand_cached: can't alloc cache size %d bytes\n",
  256. ONENAND_CACHE_SIZE);
  257. return -1;
  258. }
  259. }
  260. retlen = ONENAND_CACHE_SIZE;
  261. if (onenand_read(&onenand_mtd, onenand_cache_off, retlen,
  262. &retlen, onenand_cache) != 0 ||
  263. retlen != ONENAND_CACHE_SIZE) {
  264. printf("read_onenand_cached: error reading nand off %#x size %d bytes\n",
  265. onenand_cache_off, ONENAND_CACHE_SIZE);
  266. return -1;
  267. }
  268. }
  269. cpy_bytes = onenand_cache_off + ONENAND_CACHE_SIZE - (off + bytes_read);
  270. if (cpy_bytes > size - bytes_read)
  271. cpy_bytes = size - bytes_read;
  272. memcpy(buf + bytes_read,
  273. onenand_cache + off + bytes_read - onenand_cache_off,
  274. cpy_bytes);
  275. bytes_read += cpy_bytes;
  276. }
  277. return bytes_read;
  278. }
  279. static void *get_fl_mem_onenand(u32 off, u32 size, void *ext_buf)
  280. {
  281. u_char *buf = ext_buf ? (u_char *)ext_buf : (u_char *)malloc(size);
  282. if (NULL == buf) {
  283. printf("get_fl_mem_onenand: can't alloc %d bytes\n", size);
  284. return NULL;
  285. }
  286. if (read_onenand_cached(off, size, buf) < 0) {
  287. if (!ext_buf)
  288. free(buf);
  289. return NULL;
  290. }
  291. return buf;
  292. }
  293. static void *get_node_mem_onenand(u32 off, void *ext_buf)
  294. {
  295. struct jffs2_unknown_node node;
  296. void *ret = NULL;
  297. if (NULL == get_fl_mem_onenand(off, sizeof(node), &node))
  298. return NULL;
  299. ret = get_fl_mem_onenand(off, node.magic ==
  300. JFFS2_MAGIC_BITMASK ? node.totlen : sizeof(node),
  301. ext_buf);
  302. if (!ret) {
  303. printf("off = %#x magic %#x type %#x node.totlen = %d\n",
  304. off, node.magic, node.nodetype, node.totlen);
  305. }
  306. return ret;
  307. }
  308. static void put_fl_mem_onenand(void *buf)
  309. {
  310. free(buf);
  311. }
  312. #endif
  313. #if defined(CONFIG_CMD_FLASH)
  314. /*
  315. * Support for jffs2 on top of NOR-flash
  316. *
  317. * NOR flash memory is mapped in processor's address space,
  318. * just return address.
  319. */
  320. static inline void *get_fl_mem_nor(u32 off, u32 size, void *ext_buf)
  321. {
  322. u32 addr = off;
  323. struct mtdids *id = current_part->dev->id;
  324. extern flash_info_t flash_info[];
  325. flash_info_t *flash = &flash_info[id->num];
  326. addr += flash->start[0];
  327. if (ext_buf) {
  328. memcpy(ext_buf, (void *)addr, size);
  329. return ext_buf;
  330. }
  331. return (void*)addr;
  332. }
  333. static inline void *get_node_mem_nor(u32 off, void *ext_buf)
  334. {
  335. struct jffs2_unknown_node *pNode;
  336. /* pNode will point directly to flash - don't provide external buffer
  337. and don't care about size */
  338. pNode = get_fl_mem_nor(off, 0, NULL);
  339. return (void *)get_fl_mem_nor(off, pNode->magic == JFFS2_MAGIC_BITMASK ?
  340. pNode->totlen : sizeof(*pNode), ext_buf);
  341. }
  342. #endif
  343. /*
  344. * Generic jffs2 raw memory and node read routines.
  345. *
  346. */
  347. static inline void *get_fl_mem(u32 off, u32 size, void *ext_buf)
  348. {
  349. struct mtdids *id = current_part->dev->id;
  350. switch(id->type) {
  351. #if defined(CONFIG_CMD_FLASH)
  352. case MTD_DEV_TYPE_NOR:
  353. return get_fl_mem_nor(off, size, ext_buf);
  354. break;
  355. #endif
  356. #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
  357. case MTD_DEV_TYPE_NAND:
  358. return get_fl_mem_nand(off, size, ext_buf);
  359. break;
  360. #endif
  361. #if defined(CONFIG_CMD_ONENAND)
  362. case MTD_DEV_TYPE_ONENAND:
  363. return get_fl_mem_onenand(off, size, ext_buf);
  364. break;
  365. #endif
  366. default:
  367. printf("get_fl_mem: unknown device type, " \
  368. "using raw offset!\n");
  369. }
  370. return (void*)off;
  371. }
  372. static inline void *get_node_mem(u32 off, void *ext_buf)
  373. {
  374. struct mtdids *id = current_part->dev->id;
  375. switch(id->type) {
  376. #if defined(CONFIG_CMD_FLASH)
  377. case MTD_DEV_TYPE_NOR:
  378. return get_node_mem_nor(off, ext_buf);
  379. break;
  380. #endif
  381. #if defined(CONFIG_JFFS2_NAND) && \
  382. defined(CONFIG_CMD_NAND)
  383. case MTD_DEV_TYPE_NAND:
  384. return get_node_mem_nand(off, ext_buf);
  385. break;
  386. #endif
  387. #if defined(CONFIG_CMD_ONENAND)
  388. case MTD_DEV_TYPE_ONENAND:
  389. return get_node_mem_onenand(off, ext_buf);
  390. break;
  391. #endif
  392. default:
  393. printf("get_fl_mem: unknown device type, " \
  394. "using raw offset!\n");
  395. }
  396. return (void*)off;
  397. }
  398. static inline void put_fl_mem(void *buf, void *ext_buf)
  399. {
  400. struct mtdids *id = current_part->dev->id;
  401. /* If buf is the same as ext_buf, it was provided by the caller -
  402. we shouldn't free it then. */
  403. if (buf == ext_buf)
  404. return;
  405. switch (id->type) {
  406. #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
  407. case MTD_DEV_TYPE_NAND:
  408. return put_fl_mem_nand(buf);
  409. #endif
  410. #if defined(CONFIG_CMD_ONENAND)
  411. case MTD_DEV_TYPE_ONENAND:
  412. return put_fl_mem_onenand(buf);
  413. #endif
  414. }
  415. }
  416. /* Compression names */
  417. static char *compr_names[] = {
  418. "NONE",
  419. "ZERO",
  420. "RTIME",
  421. "RUBINMIPS",
  422. "COPY",
  423. "DYNRUBIN",
  424. "ZLIB",
  425. #if defined(CONFIG_JFFS2_LZO)
  426. "LZO",
  427. #endif
  428. };
  429. /* Memory management */
  430. struct mem_block {
  431. u32 index;
  432. struct mem_block *next;
  433. struct b_node nodes[NODE_CHUNK];
  434. };
  435. static void
  436. free_nodes(struct b_list *list)
  437. {
  438. while (list->listMemBase != NULL) {
  439. struct mem_block *next = list->listMemBase->next;
  440. free( list->listMemBase );
  441. list->listMemBase = next;
  442. }
  443. }
  444. static struct b_node *
  445. add_node(struct b_list *list)
  446. {
  447. u32 index = 0;
  448. struct mem_block *memBase;
  449. struct b_node *b;
  450. memBase = list->listMemBase;
  451. if (memBase != NULL)
  452. index = memBase->index;
  453. #if 0
  454. putLabeledWord("add_node: index = ", index);
  455. putLabeledWord("add_node: memBase = ", list->listMemBase);
  456. #endif
  457. if (memBase == NULL || index >= NODE_CHUNK) {
  458. /* we need more space before we continue */
  459. memBase = mmalloc(sizeof(struct mem_block));
  460. if (memBase == NULL) {
  461. putstr("add_node: malloc failed\n");
  462. return NULL;
  463. }
  464. memBase->next = list->listMemBase;
  465. index = 0;
  466. #if 0
  467. putLabeledWord("add_node: alloced a new membase at ", *memBase);
  468. #endif
  469. }
  470. /* now we have room to add it. */
  471. b = &memBase->nodes[index];
  472. index ++;
  473. memBase->index = index;
  474. list->listMemBase = memBase;
  475. list->listCount++;
  476. return b;
  477. }
  478. static struct b_node *
  479. insert_node(struct b_list *list, u32 offset)
  480. {
  481. struct b_node *new;
  482. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  483. struct b_node *b, *prev;
  484. #endif
  485. if (!(new = add_node(list))) {
  486. putstr("add_node failed!\r\n");
  487. return NULL;
  488. }
  489. new->offset = offset;
  490. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  491. if (list->listTail != NULL && list->listCompare(new, list->listTail))
  492. prev = list->listTail;
  493. else if (list->listLast != NULL && list->listCompare(new, list->listLast))
  494. prev = list->listLast;
  495. else
  496. prev = NULL;
  497. for (b = (prev ? prev->next : list->listHead);
  498. b != NULL && list->listCompare(new, b);
  499. prev = b, b = b->next) {
  500. list->listLoops++;
  501. }
  502. if (b != NULL)
  503. list->listLast = prev;
  504. if (b != NULL) {
  505. new->next = b;
  506. if (prev != NULL)
  507. prev->next = new;
  508. else
  509. list->listHead = new;
  510. } else
  511. #endif
  512. {
  513. new->next = (struct b_node *) NULL;
  514. if (list->listTail != NULL) {
  515. list->listTail->next = new;
  516. list->listTail = new;
  517. } else {
  518. list->listTail = list->listHead = new;
  519. }
  520. }
  521. return new;
  522. }
  523. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  524. /* Sort data entries with the latest version last, so that if there
  525. * is overlapping data the latest version will be used.
  526. */
  527. static int compare_inodes(struct b_node *new, struct b_node *old)
  528. {
  529. /*
  530. * Only read in the version info from flash, not the entire inode.
  531. * This can make a big difference to speed if flash is slow.
  532. */
  533. u32 new_version;
  534. u32 old_version;
  535. get_fl_mem(new->offset + offsetof(struct jffs2_raw_inode, version),
  536. sizeof(new_version), &new_version);
  537. get_fl_mem(old->offset + offsetof(struct jffs2_raw_inode, version),
  538. sizeof(old_version), &old_version);
  539. return new_version > old_version;
  540. }
  541. /* Sort directory entries so all entries in the same directory
  542. * with the same name are grouped together, with the latest version
  543. * last. This makes it easy to eliminate all but the latest version
  544. * by marking the previous version dead by setting the inode to 0.
  545. */
  546. static int compare_dirents(struct b_node *new, struct b_node *old)
  547. {
  548. /*
  549. * Using NULL as the buffer for NOR flash prevents the entire node
  550. * being read. This makes most comparisons much quicker as only one
  551. * or two entries from the node will be used most of the time.
  552. */
  553. struct jffs2_raw_dirent *jNew = get_node_mem(new->offset, NULL);
  554. struct jffs2_raw_dirent *jOld = get_node_mem(old->offset, NULL);
  555. int cmp;
  556. int ret;
  557. if (jNew->pino != jOld->pino) {
  558. /* ascending sort by pino */
  559. ret = jNew->pino > jOld->pino;
  560. } else if (jNew->nsize != jOld->nsize) {
  561. /*
  562. * pino is the same, so use ascending sort by nsize,
  563. * so we don't do strncmp unless we really must.
  564. */
  565. ret = jNew->nsize > jOld->nsize;
  566. } else {
  567. /*
  568. * length is also the same, so use ascending sort by name
  569. */
  570. cmp = strncmp((char *)jNew->name, (char *)jOld->name,
  571. jNew->nsize);
  572. if (cmp != 0) {
  573. ret = cmp > 0;
  574. } else {
  575. /*
  576. * we have duplicate names in this directory,
  577. * so use ascending sort by version
  578. */
  579. ret = jNew->version > jOld->version;
  580. }
  581. }
  582. put_fl_mem(jNew, NULL);
  583. put_fl_mem(jOld, NULL);
  584. return ret;
  585. }
  586. #endif
  587. void
  588. jffs2_free_cache(struct part_info *part)
  589. {
  590. struct b_lists *pL;
  591. if (part->jffs2_priv != NULL) {
  592. pL = (struct b_lists *)part->jffs2_priv;
  593. free_nodes(&pL->frag);
  594. free_nodes(&pL->dir);
  595. free(pL->readbuf);
  596. free(pL);
  597. }
  598. }
  599. static u32
  600. jffs_init_1pass_list(struct part_info *part)
  601. {
  602. struct b_lists *pL;
  603. jffs2_free_cache(part);
  604. if (NULL != (part->jffs2_priv = malloc(sizeof(struct b_lists)))) {
  605. pL = (struct b_lists *)part->jffs2_priv;
  606. memset(pL, 0, sizeof(*pL));
  607. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  608. pL->dir.listCompare = compare_dirents;
  609. pL->frag.listCompare = compare_inodes;
  610. #endif
  611. }
  612. return 0;
  613. }
  614. /* find the inode from the slashless name given a parent */
  615. static long
  616. jffs2_1pass_read_inode(struct b_lists *pL, u32 inode, char *dest)
  617. {
  618. struct b_node *b;
  619. struct jffs2_raw_inode *jNode;
  620. u32 totalSize = 0;
  621. u32 latestVersion = 0;
  622. uchar *lDest;
  623. uchar *src;
  624. int i;
  625. u32 counter = 0;
  626. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  627. /* Find file size before loading any data, so fragments that
  628. * start past the end of file can be ignored. A fragment
  629. * that is partially in the file is loaded, so extra data may
  630. * be loaded up to the next 4K boundary above the file size.
  631. * This shouldn't cause trouble when loading kernel images, so
  632. * we will live with it.
  633. */
  634. for (b = pL->frag.listHead; b != NULL; b = b->next) {
  635. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  636. sizeof(struct jffs2_raw_inode), pL->readbuf);
  637. if ((inode == jNode->ino)) {
  638. /* get actual file length from the newest node */
  639. if (jNode->version >= latestVersion) {
  640. totalSize = jNode->isize;
  641. latestVersion = jNode->version;
  642. }
  643. }
  644. put_fl_mem(jNode, pL->readbuf);
  645. }
  646. /*
  647. * If no destination is provided, we are done.
  648. * Just return the total size.
  649. */
  650. if (!dest)
  651. return totalSize;
  652. #endif
  653. for (b = pL->frag.listHead; b != NULL; b = b->next) {
  654. jNode = (struct jffs2_raw_inode *) get_node_mem(b->offset,
  655. pL->readbuf);
  656. if (inode == jNode->ino) {
  657. #if 0
  658. putLabeledWord("\r\n\r\nread_inode: totlen = ", jNode->totlen);
  659. putLabeledWord("read_inode: inode = ", jNode->ino);
  660. putLabeledWord("read_inode: version = ", jNode->version);
  661. putLabeledWord("read_inode: isize = ", jNode->isize);
  662. putLabeledWord("read_inode: offset = ", jNode->offset);
  663. putLabeledWord("read_inode: csize = ", jNode->csize);
  664. putLabeledWord("read_inode: dsize = ", jNode->dsize);
  665. putLabeledWord("read_inode: compr = ", jNode->compr);
  666. putLabeledWord("read_inode: usercompr = ", jNode->usercompr);
  667. putLabeledWord("read_inode: flags = ", jNode->flags);
  668. #endif
  669. #ifndef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  670. /* get actual file length from the newest node */
  671. if (jNode->version >= latestVersion) {
  672. totalSize = jNode->isize;
  673. latestVersion = jNode->version;
  674. }
  675. #endif
  676. if(dest) {
  677. src = ((uchar *) jNode) + sizeof(struct jffs2_raw_inode);
  678. /* ignore data behind latest known EOF */
  679. if (jNode->offset > totalSize) {
  680. put_fl_mem(jNode, pL->readbuf);
  681. continue;
  682. }
  683. if (b->datacrc == CRC_UNKNOWN)
  684. b->datacrc = data_crc(jNode) ?
  685. CRC_OK : CRC_BAD;
  686. if (b->datacrc == CRC_BAD) {
  687. put_fl_mem(jNode, pL->readbuf);
  688. continue;
  689. }
  690. lDest = (uchar *) (dest + jNode->offset);
  691. #if 0
  692. putLabeledWord("read_inode: src = ", src);
  693. putLabeledWord("read_inode: dest = ", lDest);
  694. #endif
  695. switch (jNode->compr) {
  696. case JFFS2_COMPR_NONE:
  697. ldr_memcpy(lDest, src, jNode->dsize);
  698. break;
  699. case JFFS2_COMPR_ZERO:
  700. for (i = 0; i < jNode->dsize; i++)
  701. *(lDest++) = 0;
  702. break;
  703. case JFFS2_COMPR_RTIME:
  704. rtime_decompress(src, lDest, jNode->csize, jNode->dsize);
  705. break;
  706. case JFFS2_COMPR_DYNRUBIN:
  707. /* this is slow but it works */
  708. dynrubin_decompress(src, lDest, jNode->csize, jNode->dsize);
  709. break;
  710. case JFFS2_COMPR_ZLIB:
  711. zlib_decompress(src, lDest, jNode->csize, jNode->dsize);
  712. break;
  713. #if defined(CONFIG_JFFS2_LZO)
  714. case JFFS2_COMPR_LZO:
  715. lzo_decompress(src, lDest, jNode->csize, jNode->dsize);
  716. break;
  717. #endif
  718. default:
  719. /* unknown */
  720. putLabeledWord("UNKNOWN COMPRESSION METHOD = ", jNode->compr);
  721. put_fl_mem(jNode, pL->readbuf);
  722. return -1;
  723. break;
  724. }
  725. }
  726. #if 0
  727. putLabeledWord("read_inode: totalSize = ", totalSize);
  728. #endif
  729. }
  730. counter++;
  731. put_fl_mem(jNode, pL->readbuf);
  732. }
  733. #if 0
  734. putLabeledWord("read_inode: returning = ", totalSize);
  735. #endif
  736. return totalSize;
  737. }
  738. /* find the inode from the slashless name given a parent */
  739. static u32
  740. jffs2_1pass_find_inode(struct b_lists * pL, const char *name, u32 pino)
  741. {
  742. struct b_node *b;
  743. struct jffs2_raw_dirent *jDir;
  744. int len;
  745. u32 counter;
  746. u32 version = 0;
  747. u32 inode = 0;
  748. /* name is assumed slash free */
  749. len = strlen(name);
  750. counter = 0;
  751. /* we need to search all and return the inode with the highest version */
  752. for(b = pL->dir.listHead; b; b = b->next, counter++) {
  753. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  754. pL->readbuf);
  755. if ((pino == jDir->pino) && (len == jDir->nsize) &&
  756. (jDir->ino) && /* 0 for unlink */
  757. (!strncmp((char *)jDir->name, name, len))) { /* a match */
  758. if (jDir->version < version) {
  759. put_fl_mem(jDir, pL->readbuf);
  760. continue;
  761. }
  762. if (jDir->version == version && inode != 0) {
  763. /* I'm pretty sure this isn't legal */
  764. putstr(" ** ERROR ** ");
  765. putnstr(jDir->name, jDir->nsize);
  766. putLabeledWord(" has dup version =", version);
  767. }
  768. inode = jDir->ino;
  769. version = jDir->version;
  770. }
  771. #if 0
  772. putstr("\r\nfind_inode:p&l ->");
  773. putnstr(jDir->name, jDir->nsize);
  774. putstr("\r\n");
  775. putLabeledWord("pino = ", jDir->pino);
  776. putLabeledWord("nsize = ", jDir->nsize);
  777. putLabeledWord("b = ", (u32) b);
  778. putLabeledWord("counter = ", counter);
  779. #endif
  780. put_fl_mem(jDir, pL->readbuf);
  781. }
  782. return inode;
  783. }
  784. char *mkmodestr(unsigned long mode, char *str)
  785. {
  786. static const char *l = "xwr";
  787. int mask = 1, i;
  788. char c;
  789. switch (mode & S_IFMT) {
  790. case S_IFDIR: str[0] = 'd'; break;
  791. case S_IFBLK: str[0] = 'b'; break;
  792. case S_IFCHR: str[0] = 'c'; break;
  793. case S_IFIFO: str[0] = 'f'; break;
  794. case S_IFLNK: str[0] = 'l'; break;
  795. case S_IFSOCK: str[0] = 's'; break;
  796. case S_IFREG: str[0] = '-'; break;
  797. default: str[0] = '?';
  798. }
  799. for(i = 0; i < 9; i++) {
  800. c = l[i%3];
  801. str[9-i] = (mode & mask)?c:'-';
  802. mask = mask<<1;
  803. }
  804. if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
  805. if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
  806. if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
  807. str[10] = '\0';
  808. return str;
  809. }
  810. static inline void dump_stat(struct stat *st, const char *name)
  811. {
  812. char str[20];
  813. char s[64], *p;
  814. if (st->st_mtime == (time_t)(-1)) /* some ctimes really hate -1 */
  815. st->st_mtime = 1;
  816. ctime_r((time_t *)&st->st_mtime, s/*,64*/); /* newlib ctime doesn't have buflen */
  817. if ((p = strchr(s,'\n')) != NULL) *p = '\0';
  818. if ((p = strchr(s,'\r')) != NULL) *p = '\0';
  819. /*
  820. printf("%6lo %s %8ld %s %s\n", st->st_mode, mkmodestr(st->st_mode, str),
  821. st->st_size, s, name);
  822. */
  823. printf(" %s %8ld %s %s", mkmodestr(st->st_mode,str), st->st_size, s, name);
  824. }
  825. static inline u32 dump_inode(struct b_lists * pL, struct jffs2_raw_dirent *d, struct jffs2_raw_inode *i)
  826. {
  827. char fname[256];
  828. struct stat st;
  829. if(!d || !i) return -1;
  830. strncpy(fname, (char *)d->name, d->nsize);
  831. fname[d->nsize] = '\0';
  832. memset(&st,0,sizeof(st));
  833. st.st_mtime = i->mtime;
  834. st.st_mode = i->mode;
  835. st.st_ino = i->ino;
  836. st.st_size = i->isize;
  837. dump_stat(&st, fname);
  838. if (d->type == DT_LNK) {
  839. unsigned char *src = (unsigned char *) (&i[1]);
  840. putstr(" -> ");
  841. putnstr(src, (int)i->dsize);
  842. }
  843. putstr("\r\n");
  844. return 0;
  845. }
  846. /* list inodes with the given pino */
  847. static u32
  848. jffs2_1pass_list_inodes(struct b_lists * pL, u32 pino)
  849. {
  850. struct b_node *b;
  851. struct jffs2_raw_dirent *jDir;
  852. for (b = pL->dir.listHead; b; b = b->next) {
  853. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  854. pL->readbuf);
  855. if ((pino == jDir->pino) && (jDir->ino)) { /* ino=0 -> unlink */
  856. u32 i_version = 0;
  857. struct jffs2_raw_inode ojNode;
  858. struct jffs2_raw_inode *jNode, *i = NULL;
  859. struct b_node *b2 = pL->frag.listHead;
  860. while (b2) {
  861. jNode = (struct jffs2_raw_inode *)
  862. get_fl_mem(b2->offset, sizeof(ojNode), &ojNode);
  863. if (jNode->ino == jDir->ino && jNode->version >= i_version) {
  864. i_version = jNode->version;
  865. if (i)
  866. put_fl_mem(i, NULL);
  867. if (jDir->type == DT_LNK)
  868. i = get_node_mem(b2->offset,
  869. NULL);
  870. else
  871. i = get_fl_mem(b2->offset,
  872. sizeof(*i),
  873. NULL);
  874. }
  875. b2 = b2->next;
  876. }
  877. dump_inode(pL, jDir, i);
  878. put_fl_mem(i, NULL);
  879. }
  880. put_fl_mem(jDir, pL->readbuf);
  881. }
  882. return pino;
  883. }
  884. static u32
  885. jffs2_1pass_search_inode(struct b_lists * pL, const char *fname, u32 pino)
  886. {
  887. int i;
  888. char tmp[256];
  889. char working_tmp[256];
  890. char *c;
  891. /* discard any leading slash */
  892. i = 0;
  893. while (fname[i] == '/')
  894. i++;
  895. strcpy(tmp, &fname[i]);
  896. while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
  897. {
  898. strncpy(working_tmp, tmp, c - tmp);
  899. working_tmp[c - tmp] = '\0';
  900. #if 0
  901. putstr("search_inode: tmp = ");
  902. putstr(tmp);
  903. putstr("\r\n");
  904. putstr("search_inode: wtmp = ");
  905. putstr(working_tmp);
  906. putstr("\r\n");
  907. putstr("search_inode: c = ");
  908. putstr(c);
  909. putstr("\r\n");
  910. #endif
  911. for (i = 0; i < strlen(c) - 1; i++)
  912. tmp[i] = c[i + 1];
  913. tmp[i] = '\0';
  914. #if 0
  915. putstr("search_inode: post tmp = ");
  916. putstr(tmp);
  917. putstr("\r\n");
  918. #endif
  919. if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino))) {
  920. putstr("find_inode failed for name=");
  921. putstr(working_tmp);
  922. putstr("\r\n");
  923. return 0;
  924. }
  925. }
  926. /* this is for the bare filename, directories have already been mapped */
  927. if (!(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
  928. putstr("find_inode failed for name=");
  929. putstr(tmp);
  930. putstr("\r\n");
  931. return 0;
  932. }
  933. return pino;
  934. }
  935. static u32
  936. jffs2_1pass_resolve_inode(struct b_lists * pL, u32 ino)
  937. {
  938. struct b_node *b;
  939. struct b_node *b2;
  940. struct jffs2_raw_dirent *jDir;
  941. struct jffs2_raw_inode *jNode;
  942. u8 jDirFoundType = 0;
  943. u32 jDirFoundIno = 0;
  944. u32 jDirFoundPino = 0;
  945. char tmp[256];
  946. u32 version = 0;
  947. u32 pino;
  948. unsigned char *src;
  949. /* we need to search all and return the inode with the highest version */
  950. for(b = pL->dir.listHead; b; b = b->next) {
  951. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  952. pL->readbuf);
  953. if (ino == jDir->ino) {
  954. if (jDir->version < version) {
  955. put_fl_mem(jDir, pL->readbuf);
  956. continue;
  957. }
  958. if (jDir->version == version && jDirFoundType) {
  959. /* I'm pretty sure this isn't legal */
  960. putstr(" ** ERROR ** ");
  961. putnstr(jDir->name, jDir->nsize);
  962. putLabeledWord(" has dup version (resolve) = ",
  963. version);
  964. }
  965. jDirFoundType = jDir->type;
  966. jDirFoundIno = jDir->ino;
  967. jDirFoundPino = jDir->pino;
  968. version = jDir->version;
  969. }
  970. put_fl_mem(jDir, pL->readbuf);
  971. }
  972. /* now we found the right entry again. (shoulda returned inode*) */
  973. if (jDirFoundType != DT_LNK)
  974. return jDirFoundIno;
  975. /* it's a soft link so we follow it again. */
  976. b2 = pL->frag.listHead;
  977. while (b2) {
  978. jNode = (struct jffs2_raw_inode *) get_node_mem(b2->offset,
  979. pL->readbuf);
  980. if (jNode->ino == jDirFoundIno) {
  981. src = (unsigned char *)jNode + sizeof(struct jffs2_raw_inode);
  982. #if 0
  983. putLabeledWord("\t\t dsize = ", jNode->dsize);
  984. putstr("\t\t target = ");
  985. putnstr(src, jNode->dsize);
  986. putstr("\r\n");
  987. #endif
  988. strncpy(tmp, (char *)src, jNode->dsize);
  989. tmp[jNode->dsize] = '\0';
  990. put_fl_mem(jNode, pL->readbuf);
  991. break;
  992. }
  993. b2 = b2->next;
  994. put_fl_mem(jNode, pL->readbuf);
  995. }
  996. /* ok so the name of the new file to find is in tmp */
  997. /* if it starts with a slash it is root based else shared dirs */
  998. if (tmp[0] == '/')
  999. pino = 1;
  1000. else
  1001. pino = jDirFoundPino;
  1002. return jffs2_1pass_search_inode(pL, tmp, pino);
  1003. }
  1004. static u32
  1005. jffs2_1pass_search_list_inodes(struct b_lists * pL, const char *fname, u32 pino)
  1006. {
  1007. int i;
  1008. char tmp[256];
  1009. char working_tmp[256];
  1010. char *c;
  1011. /* discard any leading slash */
  1012. i = 0;
  1013. while (fname[i] == '/')
  1014. i++;
  1015. strcpy(tmp, &fname[i]);
  1016. working_tmp[0] = '\0';
  1017. while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
  1018. {
  1019. strncpy(working_tmp, tmp, c - tmp);
  1020. working_tmp[c - tmp] = '\0';
  1021. for (i = 0; i < strlen(c) - 1; i++)
  1022. tmp[i] = c[i + 1];
  1023. tmp[i] = '\0';
  1024. /* only a failure if we arent looking at top level */
  1025. if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino)) &&
  1026. (working_tmp[0])) {
  1027. putstr("find_inode failed for name=");
  1028. putstr(working_tmp);
  1029. putstr("\r\n");
  1030. return 0;
  1031. }
  1032. }
  1033. if (tmp[0] && !(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
  1034. putstr("find_inode failed for name=");
  1035. putstr(tmp);
  1036. putstr("\r\n");
  1037. return 0;
  1038. }
  1039. /* this is for the bare filename, directories have already been mapped */
  1040. if (!(pino = jffs2_1pass_list_inodes(pL, pino))) {
  1041. putstr("find_inode failed for name=");
  1042. putstr(tmp);
  1043. putstr("\r\n");
  1044. return 0;
  1045. }
  1046. return pino;
  1047. }
  1048. unsigned char
  1049. jffs2_1pass_rescan_needed(struct part_info *part)
  1050. {
  1051. struct b_node *b;
  1052. struct jffs2_unknown_node onode;
  1053. struct jffs2_unknown_node *node;
  1054. struct b_lists *pL = (struct b_lists *)part->jffs2_priv;
  1055. if (part->jffs2_priv == 0){
  1056. DEBUGF ("rescan: First time in use\n");
  1057. return 1;
  1058. }
  1059. /* if we have no list, we need to rescan */
  1060. if (pL->frag.listCount == 0) {
  1061. DEBUGF ("rescan: fraglist zero\n");
  1062. return 1;
  1063. }
  1064. /* but suppose someone reflashed a partition at the same offset... */
  1065. b = pL->dir.listHead;
  1066. while (b) {
  1067. node = (struct jffs2_unknown_node *) get_fl_mem(b->offset,
  1068. sizeof(onode), &onode);
  1069. if (node->nodetype != JFFS2_NODETYPE_DIRENT) {
  1070. DEBUGF ("rescan: fs changed beneath me? (%lx)\n",
  1071. (unsigned long) b->offset);
  1072. return 1;
  1073. }
  1074. b = b->next;
  1075. }
  1076. return 0;
  1077. }
  1078. #ifdef CONFIG_JFFS2_SUMMARY
  1079. static u32 sum_get_unaligned32(u32 *ptr)
  1080. {
  1081. u32 val;
  1082. u8 *p = (u8 *)ptr;
  1083. val = *p | (*(p + 1) << 8) | (*(p + 2) << 16) | (*(p + 3) << 24);
  1084. return __le32_to_cpu(val);
  1085. }
  1086. static u16 sum_get_unaligned16(u16 *ptr)
  1087. {
  1088. u16 val;
  1089. u8 *p = (u8 *)ptr;
  1090. val = *p | (*(p + 1) << 8);
  1091. return __le16_to_cpu(val);
  1092. }
  1093. #define dbg_summary(...) do {} while (0);
  1094. /*
  1095. * Process the stored summary information - helper function for
  1096. * jffs2_sum_scan_sumnode()
  1097. */
  1098. static int jffs2_sum_process_sum_data(struct part_info *part, uint32_t offset,
  1099. struct jffs2_raw_summary *summary,
  1100. struct b_lists *pL)
  1101. {
  1102. void *sp;
  1103. int i, pass;
  1104. void *ret;
  1105. for (pass = 0; pass < 2; pass++) {
  1106. sp = summary->sum;
  1107. for (i = 0; i < summary->sum_num; i++) {
  1108. struct jffs2_sum_unknown_flash *spu = sp;
  1109. dbg_summary("processing summary index %d\n", i);
  1110. switch (sum_get_unaligned16(&spu->nodetype)) {
  1111. case JFFS2_NODETYPE_INODE: {
  1112. struct jffs2_sum_inode_flash *spi;
  1113. if (pass) {
  1114. spi = sp;
  1115. ret = insert_node(&pL->frag,
  1116. (u32)part->offset +
  1117. offset +
  1118. sum_get_unaligned32(
  1119. &spi->offset));
  1120. if (ret == NULL)
  1121. return -1;
  1122. }
  1123. sp += JFFS2_SUMMARY_INODE_SIZE;
  1124. break;
  1125. }
  1126. case JFFS2_NODETYPE_DIRENT: {
  1127. struct jffs2_sum_dirent_flash *spd;
  1128. spd = sp;
  1129. if (pass) {
  1130. ret = insert_node(&pL->dir,
  1131. (u32) part->offset +
  1132. offset +
  1133. sum_get_unaligned32(
  1134. &spd->offset));
  1135. if (ret == NULL)
  1136. return -1;
  1137. }
  1138. sp += JFFS2_SUMMARY_DIRENT_SIZE(
  1139. spd->nsize);
  1140. break;
  1141. }
  1142. default : {
  1143. uint16_t nodetype = sum_get_unaligned16(
  1144. &spu->nodetype);
  1145. printf("Unsupported node type %x found"
  1146. " in summary!\n",
  1147. nodetype);
  1148. if ((nodetype & JFFS2_COMPAT_MASK) ==
  1149. JFFS2_FEATURE_INCOMPAT)
  1150. return -EIO;
  1151. return -EBADMSG;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. return 0;
  1157. }
  1158. /* Process the summary node - called from jffs2_scan_eraseblock() */
  1159. int jffs2_sum_scan_sumnode(struct part_info *part, uint32_t offset,
  1160. struct jffs2_raw_summary *summary, uint32_t sumsize,
  1161. struct b_lists *pL)
  1162. {
  1163. struct jffs2_unknown_node crcnode;
  1164. int ret, ofs;
  1165. uint32_t crc;
  1166. ofs = part->sector_size - sumsize;
  1167. dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
  1168. offset, offset + ofs, sumsize);
  1169. /* OK, now check for node validity and CRC */
  1170. crcnode.magic = JFFS2_MAGIC_BITMASK;
  1171. crcnode.nodetype = JFFS2_NODETYPE_SUMMARY;
  1172. crcnode.totlen = summary->totlen;
  1173. crc = crc32_no_comp(0, (uchar *)&crcnode, sizeof(crcnode)-4);
  1174. if (summary->hdr_crc != crc) {
  1175. dbg_summary("Summary node header is corrupt (bad CRC or "
  1176. "no summary at all)\n");
  1177. goto crc_err;
  1178. }
  1179. if (summary->totlen != sumsize) {
  1180. dbg_summary("Summary node is corrupt (wrong erasesize?)\n");
  1181. goto crc_err;
  1182. }
  1183. crc = crc32_no_comp(0, (uchar *)summary,
  1184. sizeof(struct jffs2_raw_summary)-8);
  1185. if (summary->node_crc != crc) {
  1186. dbg_summary("Summary node is corrupt (bad CRC)\n");
  1187. goto crc_err;
  1188. }
  1189. crc = crc32_no_comp(0, (uchar *)summary->sum,
  1190. sumsize - sizeof(struct jffs2_raw_summary));
  1191. if (summary->sum_crc != crc) {
  1192. dbg_summary("Summary node data is corrupt (bad CRC)\n");
  1193. goto crc_err;
  1194. }
  1195. if (summary->cln_mkr)
  1196. dbg_summary("Summary : CLEANMARKER node \n");
  1197. ret = jffs2_sum_process_sum_data(part, offset, summary, pL);
  1198. if (ret == -EBADMSG)
  1199. return 0;
  1200. if (ret)
  1201. return ret; /* real error */
  1202. return 1;
  1203. crc_err:
  1204. putstr("Summary node crc error, skipping summary information.\n");
  1205. return 0;
  1206. }
  1207. #endif /* CONFIG_JFFS2_SUMMARY */
  1208. #ifdef DEBUG_FRAGMENTS
  1209. static void
  1210. dump_fragments(struct b_lists *pL)
  1211. {
  1212. struct b_node *b;
  1213. struct jffs2_raw_inode ojNode;
  1214. struct jffs2_raw_inode *jNode;
  1215. putstr("\r\n\r\n******The fragment Entries******\r\n");
  1216. b = pL->frag.listHead;
  1217. while (b) {
  1218. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  1219. sizeof(ojNode), &ojNode);
  1220. putLabeledWord("\r\n\tbuild_list: FLASH_OFFSET = ", b->offset);
  1221. putLabeledWord("\tbuild_list: totlen = ", jNode->totlen);
  1222. putLabeledWord("\tbuild_list: inode = ", jNode->ino);
  1223. putLabeledWord("\tbuild_list: version = ", jNode->version);
  1224. putLabeledWord("\tbuild_list: isize = ", jNode->isize);
  1225. putLabeledWord("\tbuild_list: atime = ", jNode->atime);
  1226. putLabeledWord("\tbuild_list: offset = ", jNode->offset);
  1227. putLabeledWord("\tbuild_list: csize = ", jNode->csize);
  1228. putLabeledWord("\tbuild_list: dsize = ", jNode->dsize);
  1229. putLabeledWord("\tbuild_list: compr = ", jNode->compr);
  1230. putLabeledWord("\tbuild_list: usercompr = ", jNode->usercompr);
  1231. putLabeledWord("\tbuild_list: flags = ", jNode->flags);
  1232. putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
  1233. b = b->next;
  1234. }
  1235. }
  1236. #endif
  1237. #ifdef DEBUG_DIRENTS
  1238. static void
  1239. dump_dirents(struct b_lists *pL)
  1240. {
  1241. struct b_node *b;
  1242. struct jffs2_raw_dirent *jDir;
  1243. putstr("\r\n\r\n******The directory Entries******\r\n");
  1244. b = pL->dir.listHead;
  1245. while (b) {
  1246. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  1247. pL->readbuf);
  1248. putstr("\r\n");
  1249. putnstr(jDir->name, jDir->nsize);
  1250. putLabeledWord("\r\n\tbuild_list: magic = ", jDir->magic);
  1251. putLabeledWord("\tbuild_list: nodetype = ", jDir->nodetype);
  1252. putLabeledWord("\tbuild_list: hdr_crc = ", jDir->hdr_crc);
  1253. putLabeledWord("\tbuild_list: pino = ", jDir->pino);
  1254. putLabeledWord("\tbuild_list: version = ", jDir->version);
  1255. putLabeledWord("\tbuild_list: ino = ", jDir->ino);
  1256. putLabeledWord("\tbuild_list: mctime = ", jDir->mctime);
  1257. putLabeledWord("\tbuild_list: nsize = ", jDir->nsize);
  1258. putLabeledWord("\tbuild_list: type = ", jDir->type);
  1259. putLabeledWord("\tbuild_list: node_crc = ", jDir->node_crc);
  1260. putLabeledWord("\tbuild_list: name_crc = ", jDir->name_crc);
  1261. putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
  1262. b = b->next;
  1263. put_fl_mem(jDir, pL->readbuf);
  1264. }
  1265. }
  1266. #endif
  1267. #define DEFAULT_EMPTY_SCAN_SIZE 4096
  1268. static inline uint32_t EMPTY_SCAN_SIZE(uint32_t sector_size)
  1269. {
  1270. if (sector_size < DEFAULT_EMPTY_SCAN_SIZE)
  1271. return sector_size;
  1272. else
  1273. return DEFAULT_EMPTY_SCAN_SIZE;
  1274. }
  1275. static u32
  1276. jffs2_1pass_build_lists(struct part_info * part)
  1277. {
  1278. struct b_lists *pL;
  1279. struct jffs2_unknown_node *node;
  1280. u32 nr_sectors;
  1281. u32 i;
  1282. u32 counter4 = 0;
  1283. u32 counterF = 0;
  1284. u32 counterN = 0;
  1285. u32 max_totlen = 0;
  1286. u32 buf_size = DEFAULT_EMPTY_SCAN_SIZE;
  1287. char *buf;
  1288. nr_sectors = lldiv(part->size, part->sector_size);
  1289. /* turn off the lcd. Refreshing the lcd adds 50% overhead to the */
  1290. /* jffs2 list building enterprise nope. in newer versions the overhead is */
  1291. /* only about 5 %. not enough to inconvenience people for. */
  1292. /* lcd_off(); */
  1293. /* if we are building a list we need to refresh the cache. */
  1294. jffs_init_1pass_list(part);
  1295. pL = (struct b_lists *)part->jffs2_priv;
  1296. buf = malloc(buf_size);
  1297. puts ("Scanning JFFS2 FS: ");
  1298. /* start at the beginning of the partition */
  1299. for (i = 0; i < nr_sectors; i++) {
  1300. uint32_t sector_ofs = i * part->sector_size;
  1301. uint32_t buf_ofs = sector_ofs;
  1302. uint32_t buf_len;
  1303. uint32_t ofs, prevofs;
  1304. #ifdef CONFIG_JFFS2_SUMMARY
  1305. struct jffs2_sum_marker *sm;
  1306. void *sumptr = NULL;
  1307. uint32_t sumlen;
  1308. int ret;
  1309. #endif
  1310. WATCHDOG_RESET();
  1311. #ifdef CONFIG_JFFS2_SUMMARY
  1312. buf_len = sizeof(*sm);
  1313. /* Read as much as we want into the _end_ of the preallocated
  1314. * buffer
  1315. */
  1316. get_fl_mem(part->offset + sector_ofs + part->sector_size -
  1317. buf_len, buf_len, buf + buf_size - buf_len);
  1318. sm = (void *)buf + buf_size - sizeof(*sm);
  1319. if (sm->magic == JFFS2_SUM_MAGIC) {
  1320. sumlen = part->sector_size - sm->offset;
  1321. sumptr = buf + buf_size - sumlen;
  1322. /* Now, make sure the summary itself is available */
  1323. if (sumlen > buf_size) {
  1324. /* Need to kmalloc for this. */
  1325. sumptr = malloc(sumlen);
  1326. if (!sumptr) {
  1327. putstr("Can't get memory for summary "
  1328. "node!\n");
  1329. free(buf);
  1330. jffs2_free_cache(part);
  1331. return 0;
  1332. }
  1333. memcpy(sumptr + sumlen - buf_len, buf +
  1334. buf_size - buf_len, buf_len);
  1335. }
  1336. if (buf_len < sumlen) {
  1337. /* Need to read more so that the entire summary
  1338. * node is present
  1339. */
  1340. get_fl_mem(part->offset + sector_ofs +
  1341. part->sector_size - sumlen,
  1342. sumlen - buf_len, sumptr);
  1343. }
  1344. }
  1345. if (sumptr) {
  1346. ret = jffs2_sum_scan_sumnode(part, sector_ofs, sumptr,
  1347. sumlen, pL);
  1348. if (buf_size && sumlen > buf_size)
  1349. free(sumptr);
  1350. if (ret < 0) {
  1351. free(buf);
  1352. jffs2_free_cache(part);
  1353. return 0;
  1354. }
  1355. if (ret)
  1356. continue;
  1357. }
  1358. #endif /* CONFIG_JFFS2_SUMMARY */
  1359. buf_len = EMPTY_SCAN_SIZE(part->sector_size);
  1360. get_fl_mem((u32)part->offset + buf_ofs, buf_len, buf);
  1361. /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
  1362. ofs = 0;
  1363. /* Scan only 4KiB of 0xFF before declaring it's empty */
  1364. while (ofs < EMPTY_SCAN_SIZE(part->sector_size) &&
  1365. *(uint32_t *)(&buf[ofs]) == 0xFFFFFFFF)
  1366. ofs += 4;
  1367. if (ofs == EMPTY_SCAN_SIZE(part->sector_size))
  1368. continue;
  1369. ofs += sector_ofs;
  1370. prevofs = ofs - 1;
  1371. scan_more:
  1372. while (ofs < sector_ofs + part->sector_size) {
  1373. if (ofs == prevofs) {
  1374. printf("offset %08x already seen, skip\n", ofs);
  1375. ofs += 4;
  1376. counter4++;
  1377. continue;
  1378. }
  1379. prevofs = ofs;
  1380. if (sector_ofs + part->sector_size <
  1381. ofs + sizeof(*node))
  1382. break;
  1383. if (buf_ofs + buf_len < ofs + sizeof(*node)) {
  1384. buf_len = min_t(uint32_t, buf_size, sector_ofs
  1385. + part->sector_size - ofs);
  1386. get_fl_mem((u32)part->offset + ofs, buf_len,
  1387. buf);
  1388. buf_ofs = ofs;
  1389. }
  1390. node = (struct jffs2_unknown_node *)&buf[ofs-buf_ofs];
  1391. if (*(uint32_t *)(&buf[ofs-buf_ofs]) == 0xffffffff) {
  1392. uint32_t inbuf_ofs;
  1393. uint32_t scan_end;
  1394. ofs += 4;
  1395. scan_end = min_t(uint32_t, EMPTY_SCAN_SIZE(
  1396. part->sector_size)/8,
  1397. buf_len);
  1398. more_empty:
  1399. inbuf_ofs = ofs - buf_ofs;
  1400. while (inbuf_ofs < scan_end) {
  1401. if (*(uint32_t *)(&buf[inbuf_ofs]) !=
  1402. 0xffffffff)
  1403. goto scan_more;
  1404. inbuf_ofs += 4;
  1405. ofs += 4;
  1406. }
  1407. /* Ran off end. */
  1408. /* See how much more there is to read in this
  1409. * eraseblock...
  1410. */
  1411. buf_len = min_t(uint32_t, buf_size,
  1412. sector_ofs +
  1413. part->sector_size - ofs);
  1414. if (!buf_len) {
  1415. /* No more to read. Break out of main
  1416. * loop without marking this range of
  1417. * empty space as dirty (because it's
  1418. * not)
  1419. */
  1420. break;
  1421. }
  1422. scan_end = buf_len;
  1423. get_fl_mem((u32)part->offset + ofs, buf_len,
  1424. buf);
  1425. buf_ofs = ofs;
  1426. goto more_empty;
  1427. }
  1428. if (node->magic != JFFS2_MAGIC_BITMASK ||
  1429. !hdr_crc(node)) {
  1430. ofs += 4;
  1431. counter4++;
  1432. continue;
  1433. }
  1434. if (ofs + node->totlen >
  1435. sector_ofs + part->sector_size) {
  1436. ofs += 4;
  1437. counter4++;
  1438. continue;
  1439. }
  1440. /* if its a fragment add it */
  1441. switch (node->nodetype) {
  1442. case JFFS2_NODETYPE_INODE:
  1443. if (buf_ofs + buf_len < ofs + sizeof(struct
  1444. jffs2_raw_inode)) {
  1445. get_fl_mem((u32)part->offset + ofs,
  1446. buf_len, buf);
  1447. buf_ofs = ofs;
  1448. node = (void *)buf;
  1449. }
  1450. if (!inode_crc((struct jffs2_raw_inode *) node))
  1451. break;
  1452. if (insert_node(&pL->frag, (u32) part->offset +
  1453. ofs) == NULL) {
  1454. free(buf);
  1455. jffs2_free_cache(part);
  1456. return 0;
  1457. }
  1458. if (max_totlen < node->totlen)
  1459. max_totlen = node->totlen;
  1460. break;
  1461. case JFFS2_NODETYPE_DIRENT:
  1462. if (buf_ofs + buf_len < ofs + sizeof(struct
  1463. jffs2_raw_dirent) +
  1464. ((struct
  1465. jffs2_raw_dirent *)
  1466. node)->nsize) {
  1467. get_fl_mem((u32)part->offset + ofs,
  1468. buf_len, buf);
  1469. buf_ofs = ofs;
  1470. node = (void *)buf;
  1471. }
  1472. if (!dirent_crc((struct jffs2_raw_dirent *)
  1473. node) ||
  1474. !dirent_name_crc(
  1475. (struct
  1476. jffs2_raw_dirent *)
  1477. node))
  1478. break;
  1479. if (! (counterN%100))
  1480. puts ("\b\b. ");
  1481. if (insert_node(&pL->dir, (u32) part->offset +
  1482. ofs) == NULL) {
  1483. free(buf);
  1484. jffs2_free_cache(part);
  1485. return 0;
  1486. }
  1487. if (max_totlen < node->totlen)
  1488. max_totlen = node->totlen;
  1489. counterN++;
  1490. break;
  1491. case JFFS2_NODETYPE_CLEANMARKER:
  1492. if (node->totlen != sizeof(struct jffs2_unknown_node))
  1493. printf("OOPS Cleanmarker has bad size "
  1494. "%d != %zu\n",
  1495. node->totlen,
  1496. sizeof(struct jffs2_unknown_node));
  1497. break;
  1498. case JFFS2_NODETYPE_PADDING:
  1499. if (node->totlen < sizeof(struct jffs2_unknown_node))
  1500. printf("OOPS Padding has bad size "
  1501. "%d < %zu\n",
  1502. node->totlen,
  1503. sizeof(struct jffs2_unknown_node));
  1504. break;
  1505. case JFFS2_NODETYPE_SUMMARY:
  1506. break;
  1507. default:
  1508. printf("Unknown node type: %x len %d offset 0x%x\n",
  1509. node->nodetype,
  1510. node->totlen, ofs);
  1511. }
  1512. ofs += ((node->totlen + 3) & ~3);
  1513. counterF++;
  1514. }
  1515. }
  1516. free(buf);
  1517. putstr("\b\b done.\r\n"); /* close off the dots */
  1518. /* We don't care if malloc failed - then each read operation will
  1519. * allocate its own buffer as necessary (NAND) or will read directly
  1520. * from flash (NOR).
  1521. */
  1522. pL->readbuf = malloc(max_totlen);
  1523. /* turn the lcd back on. */
  1524. /* splash(); */
  1525. #if 0
  1526. putLabeledWord("dir entries = ", pL->dir.listCount);
  1527. putLabeledWord("frag entries = ", pL->frag.listCount);
  1528. putLabeledWord("+4 increments = ", counter4);
  1529. putLabeledWord("+file_offset increments = ", counterF);
  1530. #endif
  1531. #ifdef DEBUG_DIRENTS
  1532. dump_dirents(pL);
  1533. #endif
  1534. #ifdef DEBUG_FRAGMENTS
  1535. dump_fragments(pL);
  1536. #endif
  1537. /* give visual feedback that we are done scanning the flash */
  1538. led_blink(0x0, 0x0, 0x1, 0x1); /* off, forever, on 100ms, off 100ms */
  1539. return 1;
  1540. }
  1541. static u32
  1542. jffs2_1pass_fill_info(struct b_lists * pL, struct b_jffs2_info * piL)
  1543. {
  1544. struct b_node *b;
  1545. struct jffs2_raw_inode ojNode;
  1546. struct jffs2_raw_inode *jNode;
  1547. int i;
  1548. for (i = 0; i < JFFS2_NUM_COMPR; i++) {
  1549. piL->compr_info[i].num_frags = 0;
  1550. piL->compr_info[i].compr_sum = 0;
  1551. piL->compr_info[i].decompr_sum = 0;
  1552. }
  1553. b = pL->frag.listHead;
  1554. while (b) {
  1555. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  1556. sizeof(ojNode), &ojNode);
  1557. if (jNode->compr < JFFS2_NUM_COMPR) {
  1558. piL->compr_info[jNode->compr].num_frags++;
  1559. piL->compr_info[jNode->compr].compr_sum += jNode->csize;
  1560. piL->compr_info[jNode->compr].decompr_sum += jNode->dsize;
  1561. }
  1562. b = b->next;
  1563. }
  1564. return 0;
  1565. }
  1566. static struct b_lists *
  1567. jffs2_get_list(struct part_info * part, const char *who)
  1568. {
  1569. /* copy requested part_info struct pointer to global location */
  1570. current_part = part;
  1571. if (jffs2_1pass_rescan_needed(part)) {
  1572. if (!jffs2_1pass_build_lists(part)) {
  1573. printf("%s: Failed to scan JFFSv2 file structure\n", who);
  1574. return NULL;
  1575. }
  1576. }
  1577. return (struct b_lists *)part->jffs2_priv;
  1578. }
  1579. /* Print directory / file contents */
  1580. u32
  1581. jffs2_1pass_ls(struct part_info * part, const char *fname)
  1582. {
  1583. struct b_lists *pl;
  1584. long ret = 1;
  1585. u32 inode;
  1586. if (! (pl = jffs2_get_list(part, "ls")))
  1587. return 0;
  1588. if (! (inode = jffs2_1pass_search_list_inodes(pl, fname, 1))) {
  1589. putstr("ls: Failed to scan jffs2 file structure\r\n");
  1590. return 0;
  1591. }
  1592. #if 0
  1593. putLabeledWord("found file at inode = ", inode);
  1594. putLabeledWord("read_inode returns = ", ret);
  1595. #endif
  1596. return ret;
  1597. }
  1598. /* Load a file from flash into memory. fname can be a full path */
  1599. u32
  1600. jffs2_1pass_load(char *dest, struct part_info * part, const char *fname)
  1601. {
  1602. struct b_lists *pl;
  1603. long ret = 1;
  1604. u32 inode;
  1605. if (! (pl = jffs2_get_list(part, "load")))
  1606. return 0;
  1607. if (! (inode = jffs2_1pass_search_inode(pl, fname, 1))) {
  1608. putstr("load: Failed to find inode\r\n");
  1609. return 0;
  1610. }
  1611. /* Resolve symlinks */
  1612. if (! (inode = jffs2_1pass_resolve_inode(pl, inode))) {
  1613. putstr("load: Failed to resolve inode structure\r\n");
  1614. return 0;
  1615. }
  1616. if ((ret = jffs2_1pass_read_inode(pl, inode, dest)) < 0) {
  1617. putstr("load: Failed to read inode\r\n");
  1618. return 0;
  1619. }
  1620. DEBUGF ("load: loaded '%s' to 0x%lx (%ld bytes)\n", fname,
  1621. (unsigned long) dest, ret);
  1622. return ret;
  1623. }
  1624. /* Return information about the fs on this partition */
  1625. u32
  1626. jffs2_1pass_info(struct part_info * part)
  1627. {
  1628. struct b_jffs2_info info;
  1629. struct b_lists *pl;
  1630. int i;
  1631. if (! (pl = jffs2_get_list(part, "info")))
  1632. return 0;
  1633. jffs2_1pass_fill_info(pl, &info);
  1634. for (i = 0; i < JFFS2_NUM_COMPR; i++) {
  1635. printf ("Compression: %s\n"
  1636. "\tfrag count: %d\n"
  1637. "\tcompressed sum: %d\n"
  1638. "\tuncompressed sum: %d\n",
  1639. compr_names[i],
  1640. info.compr_info[i].num_frags,
  1641. info.compr_info[i].compr_sum,
  1642. info.compr_info[i].decompr_sum);
  1643. }
  1644. return 1;
  1645. }