jffs2_1pass.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  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. struct jffs2_raw_inode ojNew;
  530. struct jffs2_raw_inode ojOld;
  531. struct jffs2_raw_inode *jNew =
  532. (struct jffs2_raw_inode *)get_fl_mem(new->offset, sizeof(ojNew), &ojNew);
  533. struct jffs2_raw_inode *jOld =
  534. (struct jffs2_raw_inode *)get_fl_mem(old->offset, sizeof(ojOld), &ojOld);
  535. return jNew->version > jOld->version;
  536. }
  537. /* Sort directory entries so all entries in the same directory
  538. * with the same name are grouped together, with the latest version
  539. * last. This makes it easy to eliminate all but the latest version
  540. * by marking the previous version dead by setting the inode to 0.
  541. */
  542. static int compare_dirents(struct b_node *new, struct b_node *old)
  543. {
  544. struct jffs2_raw_dirent ojNew;
  545. struct jffs2_raw_dirent ojOld;
  546. struct jffs2_raw_dirent *jNew =
  547. (struct jffs2_raw_dirent *)get_fl_mem(new->offset, sizeof(ojNew), &ojNew);
  548. struct jffs2_raw_dirent *jOld =
  549. (struct jffs2_raw_dirent *)get_fl_mem(old->offset, sizeof(ojOld), &ojOld);
  550. int cmp;
  551. /* ascending sort by pino */
  552. if (jNew->pino != jOld->pino)
  553. return jNew->pino > jOld->pino;
  554. /* pino is the same, so use ascending sort by nsize, so
  555. * we don't do strncmp unless we really must.
  556. */
  557. if (jNew->nsize != jOld->nsize)
  558. return jNew->nsize > jOld->nsize;
  559. /* length is also the same, so use ascending sort by name
  560. */
  561. cmp = strncmp((char *)jNew->name, (char *)jOld->name, jNew->nsize);
  562. if (cmp != 0)
  563. return cmp > 0;
  564. /* we have duplicate names in this directory, so use ascending
  565. * sort by version
  566. */
  567. if (jNew->version > jOld->version) {
  568. /* since jNew is newer, we know jOld is not valid, so
  569. * mark it with inode 0 and it will not be used
  570. */
  571. jOld->ino = 0;
  572. return 1;
  573. }
  574. return 0;
  575. }
  576. #endif
  577. void
  578. jffs2_free_cache(struct part_info *part)
  579. {
  580. struct b_lists *pL;
  581. if (part->jffs2_priv != NULL) {
  582. pL = (struct b_lists *)part->jffs2_priv;
  583. free_nodes(&pL->frag);
  584. free_nodes(&pL->dir);
  585. free(pL->readbuf);
  586. free(pL);
  587. }
  588. }
  589. static u32
  590. jffs_init_1pass_list(struct part_info *part)
  591. {
  592. struct b_lists *pL;
  593. jffs2_free_cache(part);
  594. if (NULL != (part->jffs2_priv = malloc(sizeof(struct b_lists)))) {
  595. pL = (struct b_lists *)part->jffs2_priv;
  596. memset(pL, 0, sizeof(*pL));
  597. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  598. pL->dir.listCompare = compare_dirents;
  599. pL->frag.listCompare = compare_inodes;
  600. #endif
  601. }
  602. return 0;
  603. }
  604. /* find the inode from the slashless name given a parent */
  605. static long
  606. jffs2_1pass_read_inode(struct b_lists *pL, u32 inode, char *dest)
  607. {
  608. struct b_node *b;
  609. struct jffs2_raw_inode *jNode;
  610. u32 totalSize = 0;
  611. u32 latestVersion = 0;
  612. uchar *lDest;
  613. uchar *src;
  614. int i;
  615. u32 counter = 0;
  616. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  617. /* Find file size before loading any data, so fragments that
  618. * start past the end of file can be ignored. A fragment
  619. * that is partially in the file is loaded, so extra data may
  620. * be loaded up to the next 4K boundary above the file size.
  621. * This shouldn't cause trouble when loading kernel images, so
  622. * we will live with it.
  623. */
  624. for (b = pL->frag.listHead; b != NULL; b = b->next) {
  625. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  626. sizeof(struct jffs2_raw_inode), pL->readbuf);
  627. if ((inode == jNode->ino)) {
  628. /* get actual file length from the newest node */
  629. if (jNode->version >= latestVersion) {
  630. totalSize = jNode->isize;
  631. latestVersion = jNode->version;
  632. }
  633. }
  634. put_fl_mem(jNode, pL->readbuf);
  635. }
  636. #endif
  637. for (b = pL->frag.listHead; b != NULL; b = b->next) {
  638. jNode = (struct jffs2_raw_inode *) get_node_mem(b->offset,
  639. pL->readbuf);
  640. if ((inode == jNode->ino)) {
  641. #if 0
  642. putLabeledWord("\r\n\r\nread_inode: totlen = ", jNode->totlen);
  643. putLabeledWord("read_inode: inode = ", jNode->ino);
  644. putLabeledWord("read_inode: version = ", jNode->version);
  645. putLabeledWord("read_inode: isize = ", jNode->isize);
  646. putLabeledWord("read_inode: offset = ", jNode->offset);
  647. putLabeledWord("read_inode: csize = ", jNode->csize);
  648. putLabeledWord("read_inode: dsize = ", jNode->dsize);
  649. putLabeledWord("read_inode: compr = ", jNode->compr);
  650. putLabeledWord("read_inode: usercompr = ", jNode->usercompr);
  651. putLabeledWord("read_inode: flags = ", jNode->flags);
  652. #endif
  653. #ifndef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  654. /* get actual file length from the newest node */
  655. if (jNode->version >= latestVersion) {
  656. totalSize = jNode->isize;
  657. latestVersion = jNode->version;
  658. }
  659. #endif
  660. if(dest) {
  661. src = ((uchar *) jNode) + sizeof(struct jffs2_raw_inode);
  662. /* ignore data behind latest known EOF */
  663. if (jNode->offset > totalSize) {
  664. put_fl_mem(jNode, pL->readbuf);
  665. continue;
  666. }
  667. if (b->datacrc == CRC_UNKNOWN)
  668. b->datacrc = data_crc(jNode) ?
  669. CRC_OK : CRC_BAD;
  670. if (b->datacrc == CRC_BAD) {
  671. put_fl_mem(jNode, pL->readbuf);
  672. continue;
  673. }
  674. lDest = (uchar *) (dest + jNode->offset);
  675. #if 0
  676. putLabeledWord("read_inode: src = ", src);
  677. putLabeledWord("read_inode: dest = ", lDest);
  678. #endif
  679. switch (jNode->compr) {
  680. case JFFS2_COMPR_NONE:
  681. ldr_memcpy(lDest, src, jNode->dsize);
  682. break;
  683. case JFFS2_COMPR_ZERO:
  684. for (i = 0; i < jNode->dsize; i++)
  685. *(lDest++) = 0;
  686. break;
  687. case JFFS2_COMPR_RTIME:
  688. rtime_decompress(src, lDest, jNode->csize, jNode->dsize);
  689. break;
  690. case JFFS2_COMPR_DYNRUBIN:
  691. /* this is slow but it works */
  692. dynrubin_decompress(src, lDest, jNode->csize, jNode->dsize);
  693. break;
  694. case JFFS2_COMPR_ZLIB:
  695. zlib_decompress(src, lDest, jNode->csize, jNode->dsize);
  696. break;
  697. #if defined(CONFIG_JFFS2_LZO)
  698. case JFFS2_COMPR_LZO:
  699. lzo_decompress(src, lDest, jNode->csize, jNode->dsize);
  700. break;
  701. #endif
  702. default:
  703. /* unknown */
  704. putLabeledWord("UNKNOWN COMPRESSION METHOD = ", jNode->compr);
  705. put_fl_mem(jNode, pL->readbuf);
  706. return -1;
  707. break;
  708. }
  709. }
  710. #if 0
  711. putLabeledWord("read_inode: totalSize = ", totalSize);
  712. #endif
  713. }
  714. counter++;
  715. put_fl_mem(jNode, pL->readbuf);
  716. }
  717. #if 0
  718. putLabeledWord("read_inode: returning = ", totalSize);
  719. #endif
  720. return totalSize;
  721. }
  722. /* find the inode from the slashless name given a parent */
  723. static u32
  724. jffs2_1pass_find_inode(struct b_lists * pL, const char *name, u32 pino)
  725. {
  726. struct b_node *b;
  727. struct jffs2_raw_dirent *jDir;
  728. int len;
  729. u32 counter;
  730. u32 version = 0;
  731. u32 inode = 0;
  732. /* name is assumed slash free */
  733. len = strlen(name);
  734. counter = 0;
  735. /* we need to search all and return the inode with the highest version */
  736. for(b = pL->dir.listHead; b; b = b->next, counter++) {
  737. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  738. pL->readbuf);
  739. if ((pino == jDir->pino) && (len == jDir->nsize) &&
  740. (jDir->ino) && /* 0 for unlink */
  741. (!strncmp((char *)jDir->name, name, len))) { /* a match */
  742. if (jDir->version < version) {
  743. put_fl_mem(jDir, pL->readbuf);
  744. continue;
  745. }
  746. if (jDir->version == version && inode != 0) {
  747. /* I'm pretty sure this isn't legal */
  748. putstr(" ** ERROR ** ");
  749. putnstr(jDir->name, jDir->nsize);
  750. putLabeledWord(" has dup version =", version);
  751. }
  752. inode = jDir->ino;
  753. version = jDir->version;
  754. }
  755. #if 0
  756. putstr("\r\nfind_inode:p&l ->");
  757. putnstr(jDir->name, jDir->nsize);
  758. putstr("\r\n");
  759. putLabeledWord("pino = ", jDir->pino);
  760. putLabeledWord("nsize = ", jDir->nsize);
  761. putLabeledWord("b = ", (u32) b);
  762. putLabeledWord("counter = ", counter);
  763. #endif
  764. put_fl_mem(jDir, pL->readbuf);
  765. }
  766. return inode;
  767. }
  768. char *mkmodestr(unsigned long mode, char *str)
  769. {
  770. static const char *l = "xwr";
  771. int mask = 1, i;
  772. char c;
  773. switch (mode & S_IFMT) {
  774. case S_IFDIR: str[0] = 'd'; break;
  775. case S_IFBLK: str[0] = 'b'; break;
  776. case S_IFCHR: str[0] = 'c'; break;
  777. case S_IFIFO: str[0] = 'f'; break;
  778. case S_IFLNK: str[0] = 'l'; break;
  779. case S_IFSOCK: str[0] = 's'; break;
  780. case S_IFREG: str[0] = '-'; break;
  781. default: str[0] = '?';
  782. }
  783. for(i = 0; i < 9; i++) {
  784. c = l[i%3];
  785. str[9-i] = (mode & mask)?c:'-';
  786. mask = mask<<1;
  787. }
  788. if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
  789. if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
  790. if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
  791. str[10] = '\0';
  792. return str;
  793. }
  794. static inline void dump_stat(struct stat *st, const char *name)
  795. {
  796. char str[20];
  797. char s[64], *p;
  798. if (st->st_mtime == (time_t)(-1)) /* some ctimes really hate -1 */
  799. st->st_mtime = 1;
  800. ctime_r((time_t *)&st->st_mtime, s/*,64*/); /* newlib ctime doesn't have buflen */
  801. if ((p = strchr(s,'\n')) != NULL) *p = '\0';
  802. if ((p = strchr(s,'\r')) != NULL) *p = '\0';
  803. /*
  804. printf("%6lo %s %8ld %s %s\n", st->st_mode, mkmodestr(st->st_mode, str),
  805. st->st_size, s, name);
  806. */
  807. printf(" %s %8ld %s %s", mkmodestr(st->st_mode,str), st->st_size, s, name);
  808. }
  809. static inline u32 dump_inode(struct b_lists * pL, struct jffs2_raw_dirent *d, struct jffs2_raw_inode *i)
  810. {
  811. char fname[256];
  812. struct stat st;
  813. if(!d || !i) return -1;
  814. strncpy(fname, (char *)d->name, d->nsize);
  815. fname[d->nsize] = '\0';
  816. memset(&st,0,sizeof(st));
  817. st.st_mtime = i->mtime;
  818. st.st_mode = i->mode;
  819. st.st_ino = i->ino;
  820. st.st_size = i->isize;
  821. dump_stat(&st, fname);
  822. if (d->type == DT_LNK) {
  823. unsigned char *src = (unsigned char *) (&i[1]);
  824. putstr(" -> ");
  825. putnstr(src, (int)i->dsize);
  826. }
  827. putstr("\r\n");
  828. return 0;
  829. }
  830. /* list inodes with the given pino */
  831. static u32
  832. jffs2_1pass_list_inodes(struct b_lists * pL, u32 pino)
  833. {
  834. struct b_node *b;
  835. struct jffs2_raw_dirent *jDir;
  836. for (b = pL->dir.listHead; b; b = b->next) {
  837. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  838. pL->readbuf);
  839. if ((pino == jDir->pino) && (jDir->ino)) { /* ino=0 -> unlink */
  840. u32 i_version = 0;
  841. struct jffs2_raw_inode ojNode;
  842. struct jffs2_raw_inode *jNode, *i = NULL;
  843. struct b_node *b2 = pL->frag.listHead;
  844. while (b2) {
  845. jNode = (struct jffs2_raw_inode *)
  846. get_fl_mem(b2->offset, sizeof(ojNode), &ojNode);
  847. if (jNode->ino == jDir->ino && jNode->version >= i_version) {
  848. i_version = jNode->version;
  849. if (i)
  850. put_fl_mem(i, NULL);
  851. if (jDir->type == DT_LNK)
  852. i = get_node_mem(b2->offset,
  853. NULL);
  854. else
  855. i = get_fl_mem(b2->offset,
  856. sizeof(*i),
  857. NULL);
  858. }
  859. b2 = b2->next;
  860. }
  861. dump_inode(pL, jDir, i);
  862. put_fl_mem(i, NULL);
  863. }
  864. put_fl_mem(jDir, pL->readbuf);
  865. }
  866. return pino;
  867. }
  868. static u32
  869. jffs2_1pass_search_inode(struct b_lists * pL, const char *fname, u32 pino)
  870. {
  871. int i;
  872. char tmp[256];
  873. char working_tmp[256];
  874. char *c;
  875. /* discard any leading slash */
  876. i = 0;
  877. while (fname[i] == '/')
  878. i++;
  879. strcpy(tmp, &fname[i]);
  880. while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
  881. {
  882. strncpy(working_tmp, tmp, c - tmp);
  883. working_tmp[c - tmp] = '\0';
  884. #if 0
  885. putstr("search_inode: tmp = ");
  886. putstr(tmp);
  887. putstr("\r\n");
  888. putstr("search_inode: wtmp = ");
  889. putstr(working_tmp);
  890. putstr("\r\n");
  891. putstr("search_inode: c = ");
  892. putstr(c);
  893. putstr("\r\n");
  894. #endif
  895. for (i = 0; i < strlen(c) - 1; i++)
  896. tmp[i] = c[i + 1];
  897. tmp[i] = '\0';
  898. #if 0
  899. putstr("search_inode: post tmp = ");
  900. putstr(tmp);
  901. putstr("\r\n");
  902. #endif
  903. if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino))) {
  904. putstr("find_inode failed for name=");
  905. putstr(working_tmp);
  906. putstr("\r\n");
  907. return 0;
  908. }
  909. }
  910. /* this is for the bare filename, directories have already been mapped */
  911. if (!(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
  912. putstr("find_inode failed for name=");
  913. putstr(tmp);
  914. putstr("\r\n");
  915. return 0;
  916. }
  917. return pino;
  918. }
  919. static u32
  920. jffs2_1pass_resolve_inode(struct b_lists * pL, u32 ino)
  921. {
  922. struct b_node *b;
  923. struct b_node *b2;
  924. struct jffs2_raw_dirent *jDir;
  925. struct jffs2_raw_inode *jNode;
  926. u8 jDirFoundType = 0;
  927. u32 jDirFoundIno = 0;
  928. u32 jDirFoundPino = 0;
  929. char tmp[256];
  930. u32 version = 0;
  931. u32 pino;
  932. unsigned char *src;
  933. /* we need to search all and return the inode with the highest version */
  934. for(b = pL->dir.listHead; b; b = b->next) {
  935. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  936. pL->readbuf);
  937. if (ino == jDir->ino) {
  938. if (jDir->version < version) {
  939. put_fl_mem(jDir, pL->readbuf);
  940. continue;
  941. }
  942. if (jDir->version == version && jDirFoundType) {
  943. /* I'm pretty sure this isn't legal */
  944. putstr(" ** ERROR ** ");
  945. putnstr(jDir->name, jDir->nsize);
  946. putLabeledWord(" has dup version (resolve) = ",
  947. version);
  948. }
  949. jDirFoundType = jDir->type;
  950. jDirFoundIno = jDir->ino;
  951. jDirFoundPino = jDir->pino;
  952. version = jDir->version;
  953. }
  954. put_fl_mem(jDir, pL->readbuf);
  955. }
  956. /* now we found the right entry again. (shoulda returned inode*) */
  957. if (jDirFoundType != DT_LNK)
  958. return jDirFoundIno;
  959. /* it's a soft link so we follow it again. */
  960. b2 = pL->frag.listHead;
  961. while (b2) {
  962. jNode = (struct jffs2_raw_inode *) get_node_mem(b2->offset,
  963. pL->readbuf);
  964. if (jNode->ino == jDirFoundIno) {
  965. src = (unsigned char *)jNode + sizeof(struct jffs2_raw_inode);
  966. #if 0
  967. putLabeledWord("\t\t dsize = ", jNode->dsize);
  968. putstr("\t\t target = ");
  969. putnstr(src, jNode->dsize);
  970. putstr("\r\n");
  971. #endif
  972. strncpy(tmp, (char *)src, jNode->dsize);
  973. tmp[jNode->dsize] = '\0';
  974. put_fl_mem(jNode, pL->readbuf);
  975. break;
  976. }
  977. b2 = b2->next;
  978. put_fl_mem(jNode, pL->readbuf);
  979. }
  980. /* ok so the name of the new file to find is in tmp */
  981. /* if it starts with a slash it is root based else shared dirs */
  982. if (tmp[0] == '/')
  983. pino = 1;
  984. else
  985. pino = jDirFoundPino;
  986. return jffs2_1pass_search_inode(pL, tmp, pino);
  987. }
  988. static u32
  989. jffs2_1pass_search_list_inodes(struct b_lists * pL, const char *fname, u32 pino)
  990. {
  991. int i;
  992. char tmp[256];
  993. char working_tmp[256];
  994. char *c;
  995. /* discard any leading slash */
  996. i = 0;
  997. while (fname[i] == '/')
  998. i++;
  999. strcpy(tmp, &fname[i]);
  1000. working_tmp[0] = '\0';
  1001. while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
  1002. {
  1003. strncpy(working_tmp, tmp, c - tmp);
  1004. working_tmp[c - tmp] = '\0';
  1005. for (i = 0; i < strlen(c) - 1; i++)
  1006. tmp[i] = c[i + 1];
  1007. tmp[i] = '\0';
  1008. /* only a failure if we arent looking at top level */
  1009. if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino)) &&
  1010. (working_tmp[0])) {
  1011. putstr("find_inode failed for name=");
  1012. putstr(working_tmp);
  1013. putstr("\r\n");
  1014. return 0;
  1015. }
  1016. }
  1017. if (tmp[0] && !(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
  1018. putstr("find_inode failed for name=");
  1019. putstr(tmp);
  1020. putstr("\r\n");
  1021. return 0;
  1022. }
  1023. /* this is for the bare filename, directories have already been mapped */
  1024. if (!(pino = jffs2_1pass_list_inodes(pL, pino))) {
  1025. putstr("find_inode failed for name=");
  1026. putstr(tmp);
  1027. putstr("\r\n");
  1028. return 0;
  1029. }
  1030. return pino;
  1031. }
  1032. unsigned char
  1033. jffs2_1pass_rescan_needed(struct part_info *part)
  1034. {
  1035. struct b_node *b;
  1036. struct jffs2_unknown_node onode;
  1037. struct jffs2_unknown_node *node;
  1038. struct b_lists *pL = (struct b_lists *)part->jffs2_priv;
  1039. if (part->jffs2_priv == 0){
  1040. DEBUGF ("rescan: First time in use\n");
  1041. return 1;
  1042. }
  1043. /* if we have no list, we need to rescan */
  1044. if (pL->frag.listCount == 0) {
  1045. DEBUGF ("rescan: fraglist zero\n");
  1046. return 1;
  1047. }
  1048. /* but suppose someone reflashed a partition at the same offset... */
  1049. b = pL->dir.listHead;
  1050. while (b) {
  1051. node = (struct jffs2_unknown_node *) get_fl_mem(b->offset,
  1052. sizeof(onode), &onode);
  1053. if (node->nodetype != JFFS2_NODETYPE_DIRENT) {
  1054. DEBUGF ("rescan: fs changed beneath me? (%lx)\n",
  1055. (unsigned long) b->offset);
  1056. return 1;
  1057. }
  1058. b = b->next;
  1059. }
  1060. return 0;
  1061. }
  1062. #ifdef CONFIG_JFFS2_SUMMARY
  1063. static u32 sum_get_unaligned32(u32 *ptr)
  1064. {
  1065. u32 val;
  1066. u8 *p = (u8 *)ptr;
  1067. val = *p | (*(p + 1) << 8) | (*(p + 2) << 16) | (*(p + 3) << 24);
  1068. return __le32_to_cpu(val);
  1069. }
  1070. static u16 sum_get_unaligned16(u16 *ptr)
  1071. {
  1072. u16 val;
  1073. u8 *p = (u8 *)ptr;
  1074. val = *p | (*(p + 1) << 8);
  1075. return __le16_to_cpu(val);
  1076. }
  1077. #define dbg_summary(...) do {} while (0);
  1078. /*
  1079. * Process the stored summary information - helper function for
  1080. * jffs2_sum_scan_sumnode()
  1081. */
  1082. static int jffs2_sum_process_sum_data(struct part_info *part, uint32_t offset,
  1083. struct jffs2_raw_summary *summary,
  1084. struct b_lists *pL)
  1085. {
  1086. void *sp;
  1087. int i, pass;
  1088. void *ret;
  1089. for (pass = 0; pass < 2; pass++) {
  1090. sp = summary->sum;
  1091. for (i = 0; i < summary->sum_num; i++) {
  1092. struct jffs2_sum_unknown_flash *spu = sp;
  1093. dbg_summary("processing summary index %d\n", i);
  1094. switch (sum_get_unaligned16(&spu->nodetype)) {
  1095. case JFFS2_NODETYPE_INODE: {
  1096. struct jffs2_sum_inode_flash *spi;
  1097. if (pass) {
  1098. spi = sp;
  1099. ret = insert_node(&pL->frag,
  1100. (u32)part->offset +
  1101. offset +
  1102. sum_get_unaligned32(
  1103. &spi->offset));
  1104. if (ret == NULL)
  1105. return -1;
  1106. }
  1107. sp += JFFS2_SUMMARY_INODE_SIZE;
  1108. break;
  1109. }
  1110. case JFFS2_NODETYPE_DIRENT: {
  1111. struct jffs2_sum_dirent_flash *spd;
  1112. spd = sp;
  1113. if (pass) {
  1114. ret = insert_node(&pL->dir,
  1115. (u32) part->offset +
  1116. offset +
  1117. sum_get_unaligned32(
  1118. &spd->offset));
  1119. if (ret == NULL)
  1120. return -1;
  1121. }
  1122. sp += JFFS2_SUMMARY_DIRENT_SIZE(
  1123. spd->nsize);
  1124. break;
  1125. }
  1126. default : {
  1127. uint16_t nodetype = sum_get_unaligned16(
  1128. &spu->nodetype);
  1129. printf("Unsupported node type %x found"
  1130. " in summary!\n",
  1131. nodetype);
  1132. if ((nodetype & JFFS2_COMPAT_MASK) ==
  1133. JFFS2_FEATURE_INCOMPAT)
  1134. return -EIO;
  1135. return -EBADMSG;
  1136. }
  1137. }
  1138. }
  1139. }
  1140. return 0;
  1141. }
  1142. /* Process the summary node - called from jffs2_scan_eraseblock() */
  1143. int jffs2_sum_scan_sumnode(struct part_info *part, uint32_t offset,
  1144. struct jffs2_raw_summary *summary, uint32_t sumsize,
  1145. struct b_lists *pL)
  1146. {
  1147. struct jffs2_unknown_node crcnode;
  1148. int ret, ofs;
  1149. uint32_t crc;
  1150. ofs = part->sector_size - sumsize;
  1151. dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
  1152. offset, offset + ofs, sumsize);
  1153. /* OK, now check for node validity and CRC */
  1154. crcnode.magic = JFFS2_MAGIC_BITMASK;
  1155. crcnode.nodetype = JFFS2_NODETYPE_SUMMARY;
  1156. crcnode.totlen = summary->totlen;
  1157. crc = crc32_no_comp(0, (uchar *)&crcnode, sizeof(crcnode)-4);
  1158. if (summary->hdr_crc != crc) {
  1159. dbg_summary("Summary node header is corrupt (bad CRC or "
  1160. "no summary at all)\n");
  1161. goto crc_err;
  1162. }
  1163. if (summary->totlen != sumsize) {
  1164. dbg_summary("Summary node is corrupt (wrong erasesize?)\n");
  1165. goto crc_err;
  1166. }
  1167. crc = crc32_no_comp(0, (uchar *)summary,
  1168. sizeof(struct jffs2_raw_summary)-8);
  1169. if (summary->node_crc != crc) {
  1170. dbg_summary("Summary node is corrupt (bad CRC)\n");
  1171. goto crc_err;
  1172. }
  1173. crc = crc32_no_comp(0, (uchar *)summary->sum,
  1174. sumsize - sizeof(struct jffs2_raw_summary));
  1175. if (summary->sum_crc != crc) {
  1176. dbg_summary("Summary node data is corrupt (bad CRC)\n");
  1177. goto crc_err;
  1178. }
  1179. if (summary->cln_mkr)
  1180. dbg_summary("Summary : CLEANMARKER node \n");
  1181. ret = jffs2_sum_process_sum_data(part, offset, summary, pL);
  1182. if (ret == -EBADMSG)
  1183. return 0;
  1184. if (ret)
  1185. return ret; /* real error */
  1186. return 1;
  1187. crc_err:
  1188. putstr("Summary node crc error, skipping summary information.\n");
  1189. return 0;
  1190. }
  1191. #endif /* CONFIG_JFFS2_SUMMARY */
  1192. #ifdef DEBUG_FRAGMENTS
  1193. static void
  1194. dump_fragments(struct b_lists *pL)
  1195. {
  1196. struct b_node *b;
  1197. struct jffs2_raw_inode ojNode;
  1198. struct jffs2_raw_inode *jNode;
  1199. putstr("\r\n\r\n******The fragment Entries******\r\n");
  1200. b = pL->frag.listHead;
  1201. while (b) {
  1202. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  1203. sizeof(ojNode), &ojNode);
  1204. putLabeledWord("\r\n\tbuild_list: FLASH_OFFSET = ", b->offset);
  1205. putLabeledWord("\tbuild_list: totlen = ", jNode->totlen);
  1206. putLabeledWord("\tbuild_list: inode = ", jNode->ino);
  1207. putLabeledWord("\tbuild_list: version = ", jNode->version);
  1208. putLabeledWord("\tbuild_list: isize = ", jNode->isize);
  1209. putLabeledWord("\tbuild_list: atime = ", jNode->atime);
  1210. putLabeledWord("\tbuild_list: offset = ", jNode->offset);
  1211. putLabeledWord("\tbuild_list: csize = ", jNode->csize);
  1212. putLabeledWord("\tbuild_list: dsize = ", jNode->dsize);
  1213. putLabeledWord("\tbuild_list: compr = ", jNode->compr);
  1214. putLabeledWord("\tbuild_list: usercompr = ", jNode->usercompr);
  1215. putLabeledWord("\tbuild_list: flags = ", jNode->flags);
  1216. putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
  1217. b = b->next;
  1218. }
  1219. }
  1220. #endif
  1221. #ifdef DEBUG_DIRENTS
  1222. static void
  1223. dump_dirents(struct b_lists *pL)
  1224. {
  1225. struct b_node *b;
  1226. struct jffs2_raw_dirent *jDir;
  1227. putstr("\r\n\r\n******The directory Entries******\r\n");
  1228. b = pL->dir.listHead;
  1229. while (b) {
  1230. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  1231. pL->readbuf);
  1232. putstr("\r\n");
  1233. putnstr(jDir->name, jDir->nsize);
  1234. putLabeledWord("\r\n\tbuild_list: magic = ", jDir->magic);
  1235. putLabeledWord("\tbuild_list: nodetype = ", jDir->nodetype);
  1236. putLabeledWord("\tbuild_list: hdr_crc = ", jDir->hdr_crc);
  1237. putLabeledWord("\tbuild_list: pino = ", jDir->pino);
  1238. putLabeledWord("\tbuild_list: version = ", jDir->version);
  1239. putLabeledWord("\tbuild_list: ino = ", jDir->ino);
  1240. putLabeledWord("\tbuild_list: mctime = ", jDir->mctime);
  1241. putLabeledWord("\tbuild_list: nsize = ", jDir->nsize);
  1242. putLabeledWord("\tbuild_list: type = ", jDir->type);
  1243. putLabeledWord("\tbuild_list: node_crc = ", jDir->node_crc);
  1244. putLabeledWord("\tbuild_list: name_crc = ", jDir->name_crc);
  1245. putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
  1246. b = b->next;
  1247. put_fl_mem(jDir, pL->readbuf);
  1248. }
  1249. }
  1250. #endif
  1251. #define DEFAULT_EMPTY_SCAN_SIZE 4096
  1252. static inline uint32_t EMPTY_SCAN_SIZE(uint32_t sector_size)
  1253. {
  1254. if (sector_size < DEFAULT_EMPTY_SCAN_SIZE)
  1255. return sector_size;
  1256. else
  1257. return DEFAULT_EMPTY_SCAN_SIZE;
  1258. }
  1259. static u32
  1260. jffs2_1pass_build_lists(struct part_info * part)
  1261. {
  1262. struct b_lists *pL;
  1263. struct jffs2_unknown_node *node;
  1264. u32 nr_sectors;
  1265. u32 i;
  1266. u32 counter4 = 0;
  1267. u32 counterF = 0;
  1268. u32 counterN = 0;
  1269. u32 max_totlen = 0;
  1270. u32 buf_size = DEFAULT_EMPTY_SCAN_SIZE;
  1271. char *buf;
  1272. nr_sectors = lldiv(part->size, part->sector_size);
  1273. /* turn off the lcd. Refreshing the lcd adds 50% overhead to the */
  1274. /* jffs2 list building enterprise nope. in newer versions the overhead is */
  1275. /* only about 5 %. not enough to inconvenience people for. */
  1276. /* lcd_off(); */
  1277. /* if we are building a list we need to refresh the cache. */
  1278. jffs_init_1pass_list(part);
  1279. pL = (struct b_lists *)part->jffs2_priv;
  1280. buf = malloc(buf_size);
  1281. puts ("Scanning JFFS2 FS: ");
  1282. /* start at the beginning of the partition */
  1283. for (i = 0; i < nr_sectors; i++) {
  1284. uint32_t sector_ofs = i * part->sector_size;
  1285. uint32_t buf_ofs = sector_ofs;
  1286. uint32_t buf_len;
  1287. uint32_t ofs, prevofs;
  1288. #ifdef CONFIG_JFFS2_SUMMARY
  1289. struct jffs2_sum_marker *sm;
  1290. void *sumptr = NULL;
  1291. uint32_t sumlen;
  1292. int ret;
  1293. #endif
  1294. WATCHDOG_RESET();
  1295. #ifdef CONFIG_JFFS2_SUMMARY
  1296. buf_len = sizeof(*sm);
  1297. /* Read as much as we want into the _end_ of the preallocated
  1298. * buffer
  1299. */
  1300. get_fl_mem(part->offset + sector_ofs + part->sector_size -
  1301. buf_len, buf_len, buf + buf_size - buf_len);
  1302. sm = (void *)buf + buf_size - sizeof(*sm);
  1303. if (sm->magic == JFFS2_SUM_MAGIC) {
  1304. sumlen = part->sector_size - sm->offset;
  1305. sumptr = buf + buf_size - sumlen;
  1306. /* Now, make sure the summary itself is available */
  1307. if (sumlen > buf_size) {
  1308. /* Need to kmalloc for this. */
  1309. sumptr = malloc(sumlen);
  1310. if (!sumptr) {
  1311. putstr("Can't get memory for summary "
  1312. "node!\n");
  1313. free(buf);
  1314. jffs2_free_cache(part);
  1315. return 0;
  1316. }
  1317. memcpy(sumptr + sumlen - buf_len, buf +
  1318. buf_size - buf_len, buf_len);
  1319. }
  1320. if (buf_len < sumlen) {
  1321. /* Need to read more so that the entire summary
  1322. * node is present
  1323. */
  1324. get_fl_mem(part->offset + sector_ofs +
  1325. part->sector_size - sumlen,
  1326. sumlen - buf_len, sumptr);
  1327. }
  1328. }
  1329. if (sumptr) {
  1330. ret = jffs2_sum_scan_sumnode(part, sector_ofs, sumptr,
  1331. sumlen, pL);
  1332. if (buf_size && sumlen > buf_size)
  1333. free(sumptr);
  1334. if (ret < 0) {
  1335. free(buf);
  1336. jffs2_free_cache(part);
  1337. return 0;
  1338. }
  1339. if (ret)
  1340. continue;
  1341. }
  1342. #endif /* CONFIG_JFFS2_SUMMARY */
  1343. buf_len = EMPTY_SCAN_SIZE(part->sector_size);
  1344. get_fl_mem((u32)part->offset + buf_ofs, buf_len, buf);
  1345. /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
  1346. ofs = 0;
  1347. /* Scan only 4KiB of 0xFF before declaring it's empty */
  1348. while (ofs < EMPTY_SCAN_SIZE(part->sector_size) &&
  1349. *(uint32_t *)(&buf[ofs]) == 0xFFFFFFFF)
  1350. ofs += 4;
  1351. if (ofs == EMPTY_SCAN_SIZE(part->sector_size))
  1352. continue;
  1353. ofs += sector_ofs;
  1354. prevofs = ofs - 1;
  1355. scan_more:
  1356. while (ofs < sector_ofs + part->sector_size) {
  1357. if (ofs == prevofs) {
  1358. printf("offset %08x already seen, skip\n", ofs);
  1359. ofs += 4;
  1360. counter4++;
  1361. continue;
  1362. }
  1363. prevofs = ofs;
  1364. if (sector_ofs + part->sector_size <
  1365. ofs + sizeof(*node))
  1366. break;
  1367. if (buf_ofs + buf_len < ofs + sizeof(*node)) {
  1368. buf_len = min_t(uint32_t, buf_size, sector_ofs
  1369. + part->sector_size - ofs);
  1370. get_fl_mem((u32)part->offset + ofs, buf_len,
  1371. buf);
  1372. buf_ofs = ofs;
  1373. }
  1374. node = (struct jffs2_unknown_node *)&buf[ofs-buf_ofs];
  1375. if (*(uint32_t *)(&buf[ofs-buf_ofs]) == 0xffffffff) {
  1376. uint32_t inbuf_ofs;
  1377. uint32_t scan_end;
  1378. ofs += 4;
  1379. scan_end = min_t(uint32_t, EMPTY_SCAN_SIZE(
  1380. part->sector_size)/8,
  1381. buf_len);
  1382. more_empty:
  1383. inbuf_ofs = ofs - buf_ofs;
  1384. while (inbuf_ofs < scan_end) {
  1385. if (*(uint32_t *)(&buf[inbuf_ofs]) !=
  1386. 0xffffffff)
  1387. goto scan_more;
  1388. inbuf_ofs += 4;
  1389. ofs += 4;
  1390. }
  1391. /* Ran off end. */
  1392. /* See how much more there is to read in this
  1393. * eraseblock...
  1394. */
  1395. buf_len = min_t(uint32_t, buf_size,
  1396. sector_ofs +
  1397. part->sector_size - ofs);
  1398. if (!buf_len) {
  1399. /* No more to read. Break out of main
  1400. * loop without marking this range of
  1401. * empty space as dirty (because it's
  1402. * not)
  1403. */
  1404. break;
  1405. }
  1406. scan_end = buf_len;
  1407. get_fl_mem((u32)part->offset + ofs, buf_len,
  1408. buf);
  1409. buf_ofs = ofs;
  1410. goto more_empty;
  1411. }
  1412. if (node->magic != JFFS2_MAGIC_BITMASK ||
  1413. !hdr_crc(node)) {
  1414. ofs += 4;
  1415. counter4++;
  1416. continue;
  1417. }
  1418. if (ofs + node->totlen >
  1419. sector_ofs + part->sector_size) {
  1420. ofs += 4;
  1421. counter4++;
  1422. continue;
  1423. }
  1424. /* if its a fragment add it */
  1425. switch (node->nodetype) {
  1426. case JFFS2_NODETYPE_INODE:
  1427. if (buf_ofs + buf_len < ofs + sizeof(struct
  1428. jffs2_raw_inode)) {
  1429. get_fl_mem((u32)part->offset + ofs,
  1430. buf_len, buf);
  1431. buf_ofs = ofs;
  1432. node = (void *)buf;
  1433. }
  1434. if (!inode_crc((struct jffs2_raw_inode *) node))
  1435. break;
  1436. if (insert_node(&pL->frag, (u32) part->offset +
  1437. ofs) == NULL) {
  1438. free(buf);
  1439. jffs2_free_cache(part);
  1440. return 0;
  1441. }
  1442. if (max_totlen < node->totlen)
  1443. max_totlen = node->totlen;
  1444. break;
  1445. case JFFS2_NODETYPE_DIRENT:
  1446. if (buf_ofs + buf_len < ofs + sizeof(struct
  1447. jffs2_raw_dirent) +
  1448. ((struct
  1449. jffs2_raw_dirent *)
  1450. node)->nsize) {
  1451. get_fl_mem((u32)part->offset + ofs,
  1452. buf_len, buf);
  1453. buf_ofs = ofs;
  1454. node = (void *)buf;
  1455. }
  1456. if (!dirent_crc((struct jffs2_raw_dirent *)
  1457. node) ||
  1458. !dirent_name_crc(
  1459. (struct
  1460. jffs2_raw_dirent *)
  1461. node))
  1462. break;
  1463. if (! (counterN%100))
  1464. puts ("\b\b. ");
  1465. if (insert_node(&pL->dir, (u32) part->offset +
  1466. ofs) == NULL) {
  1467. free(buf);
  1468. jffs2_free_cache(part);
  1469. return 0;
  1470. }
  1471. if (max_totlen < node->totlen)
  1472. max_totlen = node->totlen;
  1473. counterN++;
  1474. break;
  1475. case JFFS2_NODETYPE_CLEANMARKER:
  1476. if (node->totlen != sizeof(struct jffs2_unknown_node))
  1477. printf("OOPS Cleanmarker has bad size "
  1478. "%d != %zu\n",
  1479. node->totlen,
  1480. sizeof(struct jffs2_unknown_node));
  1481. break;
  1482. case JFFS2_NODETYPE_PADDING:
  1483. if (node->totlen < sizeof(struct jffs2_unknown_node))
  1484. printf("OOPS Padding has bad size "
  1485. "%d < %zu\n",
  1486. node->totlen,
  1487. sizeof(struct jffs2_unknown_node));
  1488. break;
  1489. case JFFS2_NODETYPE_SUMMARY:
  1490. break;
  1491. default:
  1492. printf("Unknown node type: %x len %d offset 0x%x\n",
  1493. node->nodetype,
  1494. node->totlen, ofs);
  1495. }
  1496. ofs += ((node->totlen + 3) & ~3);
  1497. counterF++;
  1498. }
  1499. }
  1500. free(buf);
  1501. putstr("\b\b done.\r\n"); /* close off the dots */
  1502. /* We don't care if malloc failed - then each read operation will
  1503. * allocate its own buffer as necessary (NAND) or will read directly
  1504. * from flash (NOR).
  1505. */
  1506. pL->readbuf = malloc(max_totlen);
  1507. /* turn the lcd back on. */
  1508. /* splash(); */
  1509. #if 0
  1510. putLabeledWord("dir entries = ", pL->dir.listCount);
  1511. putLabeledWord("frag entries = ", pL->frag.listCount);
  1512. putLabeledWord("+4 increments = ", counter4);
  1513. putLabeledWord("+file_offset increments = ", counterF);
  1514. #endif
  1515. #ifdef DEBUG_DIRENTS
  1516. dump_dirents(pL);
  1517. #endif
  1518. #ifdef DEBUG_FRAGMENTS
  1519. dump_fragments(pL);
  1520. #endif
  1521. /* give visual feedback that we are done scanning the flash */
  1522. led_blink(0x0, 0x0, 0x1, 0x1); /* off, forever, on 100ms, off 100ms */
  1523. return 1;
  1524. }
  1525. static u32
  1526. jffs2_1pass_fill_info(struct b_lists * pL, struct b_jffs2_info * piL)
  1527. {
  1528. struct b_node *b;
  1529. struct jffs2_raw_inode ojNode;
  1530. struct jffs2_raw_inode *jNode;
  1531. int i;
  1532. for (i = 0; i < JFFS2_NUM_COMPR; i++) {
  1533. piL->compr_info[i].num_frags = 0;
  1534. piL->compr_info[i].compr_sum = 0;
  1535. piL->compr_info[i].decompr_sum = 0;
  1536. }
  1537. b = pL->frag.listHead;
  1538. while (b) {
  1539. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  1540. sizeof(ojNode), &ojNode);
  1541. if (jNode->compr < JFFS2_NUM_COMPR) {
  1542. piL->compr_info[jNode->compr].num_frags++;
  1543. piL->compr_info[jNode->compr].compr_sum += jNode->csize;
  1544. piL->compr_info[jNode->compr].decompr_sum += jNode->dsize;
  1545. }
  1546. b = b->next;
  1547. }
  1548. return 0;
  1549. }
  1550. static struct b_lists *
  1551. jffs2_get_list(struct part_info * part, const char *who)
  1552. {
  1553. /* copy requested part_info struct pointer to global location */
  1554. current_part = part;
  1555. if (jffs2_1pass_rescan_needed(part)) {
  1556. if (!jffs2_1pass_build_lists(part)) {
  1557. printf("%s: Failed to scan JFFSv2 file structure\n", who);
  1558. return NULL;
  1559. }
  1560. }
  1561. return (struct b_lists *)part->jffs2_priv;
  1562. }
  1563. /* Print directory / file contents */
  1564. u32
  1565. jffs2_1pass_ls(struct part_info * part, const char *fname)
  1566. {
  1567. struct b_lists *pl;
  1568. long ret = 1;
  1569. u32 inode;
  1570. if (! (pl = jffs2_get_list(part, "ls")))
  1571. return 0;
  1572. if (! (inode = jffs2_1pass_search_list_inodes(pl, fname, 1))) {
  1573. putstr("ls: Failed to scan jffs2 file structure\r\n");
  1574. return 0;
  1575. }
  1576. #if 0
  1577. putLabeledWord("found file at inode = ", inode);
  1578. putLabeledWord("read_inode returns = ", ret);
  1579. #endif
  1580. return ret;
  1581. }
  1582. /* Load a file from flash into memory. fname can be a full path */
  1583. u32
  1584. jffs2_1pass_load(char *dest, struct part_info * part, const char *fname)
  1585. {
  1586. struct b_lists *pl;
  1587. long ret = 1;
  1588. u32 inode;
  1589. if (! (pl = jffs2_get_list(part, "load")))
  1590. return 0;
  1591. if (! (inode = jffs2_1pass_search_inode(pl, fname, 1))) {
  1592. putstr("load: Failed to find inode\r\n");
  1593. return 0;
  1594. }
  1595. /* Resolve symlinks */
  1596. if (! (inode = jffs2_1pass_resolve_inode(pl, inode))) {
  1597. putstr("load: Failed to resolve inode structure\r\n");
  1598. return 0;
  1599. }
  1600. if ((ret = jffs2_1pass_read_inode(pl, inode, dest)) < 0) {
  1601. putstr("load: Failed to read inode\r\n");
  1602. return 0;
  1603. }
  1604. DEBUGF ("load: loaded '%s' to 0x%lx (%ld bytes)\n", fname,
  1605. (unsigned long) dest, ret);
  1606. return ret;
  1607. }
  1608. /* Return information about the fs on this partition */
  1609. u32
  1610. jffs2_1pass_info(struct part_info * part)
  1611. {
  1612. struct b_jffs2_info info;
  1613. struct b_lists *pl;
  1614. int i;
  1615. if (! (pl = jffs2_get_list(part, "info")))
  1616. return 0;
  1617. jffs2_1pass_fill_info(pl, &info);
  1618. for (i = 0; i < JFFS2_NUM_COMPR; i++) {
  1619. printf ("Compression: %s\n"
  1620. "\tfrag count: %d\n"
  1621. "\tcompressed sum: %d\n"
  1622. "\tuncompressed sum: %d\n",
  1623. compr_names[i],
  1624. info.compr_info[i].num_frags,
  1625. info.compr_info[i].compr_sum,
  1626. info.compr_info[i].decompr_sum);
  1627. }
  1628. return 1;
  1629. }