jffs2_1pass.c 47 KB

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