blob: 01f1fb73e9a69061b4363656eeae3a3aa5b39906 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
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
49/* Ok, so anyone who knows the jffs2 code will probably want to get a papar
50 * bag to throw up into before reading this code. I looked through the jffs2
51 * code, the caching scheme is very elegant. I tried to keep the version
52 * for a bootloader as small and simple as possible. Instead of worring about
53 * unneccesary data copies, node scans, etc, I just optimized for the known
54 * common case, a kernel, which looks like:
55 * (1) most pages are 4096 bytes
56 * (2) version numbers are somewhat sorted in acsending order
57 * (3) multiple compressed blocks making up one page is uncommon
58 *
59 * So I create a linked list of decending version numbers (insertions at the
60 * head), and then for each page, walk down the list, until a matching page
61 * with 4096 bytes is found, and then decompress the watching pages in
62 * reverse order.
63 *
64 */
65
66/*
67 * Adapted by Nye Liu <nyet@zumanetworks.com> and
68 * Rex Feany <rfeany@zumanetworks.com>
69 * on Jan/2002 for U-Boot.
70 *
71 * Clipped out all the non-1pass functions, cleaned up warnings,
72 * wrappers, etc. No major changes to the code.
73 * Please, he really means it when he said have a paper bag
74 * handy. We needed it ;).
75 *
76 */
77
wdenk06d01db2003-03-14 20:47:52 +000078/*
79 * Bugfixing by Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>, (C) Mar/2003
80 *
81 * - overhaul of the memory management. Removed much of the "paper-bagging"
82 * in that part of the code, fixed several bugs, now frees memory when
83 * partition is changed.
84 * It's still ugly :-(
85 * - fixed a bug in jffs2_1pass_read_inode where the file length calculation
86 * was incorrect. Removed a bit of the paper-bagging as well.
87 * - removed double crc calculation for fragment headers in jffs2_private.h
88 * for speedup.
89 * - scan_empty rewritten in a more "standard" manner (non-paperbag, that is).
90 * - spinning wheel now spins depending on how much memory has been scanned
91 * - lots of small changes all over the place to "improve" readability.
92 * - implemented fragment sorting to ensure that the newest data is copied
93 * if there are multiple copies of fragments for a certain file offset.
94 *
95 * The fragment sorting feature must be enabled by CFG_JFFS2_SORT_FRAGMENTS.
96 * Sorting is done while adding fragments to the lists, which is more or less a
97 * bubble sort. This takes a lot of time, and is most probably not an issue if
98 * the boot filesystem is always mounted readonly.
99 *
100 * You should define it if the boot filesystem is mounted writable, and updates
101 * to the boot files are done by copying files to that filesystem.
102 *
103 *
104 * There's a big issue left: endianess is completely ignored in this code. Duh!
105 *
106 *
107 * You still should have paper bags at hand :-(. The code lacks more or less
108 * any comment, and is still arcane and difficult to read in places. As this
wdenkdd875c72004-01-03 21:24:46 +0000109 * might be incompatible with any new code from the jffs2 maintainers anyway,
110 * it should probably be dumped and replaced by something like jffs2reader!
wdenk06d01db2003-03-14 20:47:52 +0000111 */
112
113
wdenkfe8c2802002-11-03 00:38:21 +0000114#include <common.h>
115#include <config.h>
116#include <malloc.h>
117#include <linux/stat.h>
118#include <linux/time.h>
119
120#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
121
122#include <jffs2/jffs2.h>
123#include <jffs2/jffs2_1pass.h>
124
125#include "jffs2_private.h"
126
wdenkfe8c2802002-11-03 00:38:21 +0000127
wdenk06d01db2003-03-14 20:47:52 +0000128#define NODE_CHUNK 1024 /* size of memory allocation chunk in b_nodes */
129#define SPIN_BLKSIZE 18 /* spin after having scanned 1<<BLKSIZE bytes */
wdenkfe8c2802002-11-03 00:38:21 +0000130
wdenk06d01db2003-03-14 20:47:52 +0000131/* Debugging switches */
132#undef DEBUG_DIRENTS /* print directory entry list after scan */
133#undef DEBUG_FRAGMENTS /* print fragment list after scan */
134#undef DEBUG /* enable debugging messages */
135
136
wdenkfe8c2802002-11-03 00:38:21 +0000137#ifdef DEBUG
138# define DEBUGF(fmt,args...) printf(fmt ,##args)
139#else
140# define DEBUGF(fmt,args...)
141#endif
142
wdenkfe8c2802002-11-03 00:38:21 +0000143
wdenk06d01db2003-03-14 20:47:52 +0000144/* Compression names */
145static char *compr_names[] = {
146 "NONE",
147 "ZERO",
148 "RTIME",
149 "RUBINMIPS",
150 "COPY",
151 "DYNRUBIN",
152 "ZLIB"
153};
154
155/* Spinning wheel */
156static char spinner[] = { '|', '/', '-', '\\' };
157
158/* Memory management */
159struct mem_block {
160 u32 index;
161 struct mem_block *next;
162 struct b_node nodes[NODE_CHUNK];
163};
164
165
166static void
167free_nodes(struct b_list *list)
168{
169 while (list->listMemBase != NULL) {
170 struct mem_block *next = list->listMemBase->next;
171 free( list->listMemBase );
172 list->listMemBase = next;
173 }
174}
wdenkfe8c2802002-11-03 00:38:21 +0000175
176static struct b_node *
wdenk06d01db2003-03-14 20:47:52 +0000177add_node(struct b_list *list)
wdenkfe8c2802002-11-03 00:38:21 +0000178{
wdenk06d01db2003-03-14 20:47:52 +0000179 u32 index = 0;
180 struct mem_block *memBase;
wdenkfe8c2802002-11-03 00:38:21 +0000181 struct b_node *b;
182
wdenk06d01db2003-03-14 20:47:52 +0000183 memBase = list->listMemBase;
184 if (memBase != NULL)
185 index = memBase->index;
wdenkfe8c2802002-11-03 00:38:21 +0000186#if 0
187 putLabeledWord("add_node: index = ", index);
wdenk06d01db2003-03-14 20:47:52 +0000188 putLabeledWord("add_node: memBase = ", list->listMemBase);
wdenkfe8c2802002-11-03 00:38:21 +0000189#endif
190
wdenk06d01db2003-03-14 20:47:52 +0000191 if (memBase == NULL || index >= NODE_CHUNK) {
192 /* we need more space before we continue */
193 memBase = mmalloc(sizeof(struct mem_block));
194 if (memBase == NULL) {
wdenkfe8c2802002-11-03 00:38:21 +0000195 putstr("add_node: malloc failed\n");
196 return NULL;
197 }
wdenk06d01db2003-03-14 20:47:52 +0000198 memBase->next = list->listMemBase;
199 index = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000200#if 0
201 putLabeledWord("add_node: alloced a new membase at ", *memBase);
202#endif
203
204 }
205 /* now we have room to add it. */
wdenk06d01db2003-03-14 20:47:52 +0000206 b = &memBase->nodes[index];
207 index ++;
wdenkfe8c2802002-11-03 00:38:21 +0000208
wdenk06d01db2003-03-14 20:47:52 +0000209 memBase->index = index;
210 list->listMemBase = memBase;
211 list->listCount++;
wdenkfe8c2802002-11-03 00:38:21 +0000212 return b;
wdenkfe8c2802002-11-03 00:38:21 +0000213}
214
wdenk06d01db2003-03-14 20:47:52 +0000215static struct b_node *
216insert_node(struct b_list *list, u32 offset)
217{
218 struct b_node *new;
219#ifdef CFG_JFFS2_SORT_FRAGMENTS
220 struct b_node *b, *prev;
221#endif
222
223 if (!(new = add_node(list))) {
224 putstr("add_node failed!\r\n");
225 return NULL;
226 }
227 new->offset = offset;
228
229#ifdef CFG_JFFS2_SORT_FRAGMENTS
230 if (list->listTail != NULL && list->listCompare(new, list->listTail))
231 prev = list->listTail;
232 else if (list->listLast != NULL && list->listCompare(new, list->listLast))
233 prev = list->listLast;
234 else
235 prev = NULL;
236
237 for (b = (prev ? prev->next : list->listHead);
238 b != NULL && list->listCompare(new, b);
239 prev = b, b = b->next) {
240 list->listLoops++;
241 }
242 if (b != NULL)
243 list->listLast = prev;
244
245 if (b != NULL) {
246 new->next = b;
247 if (prev != NULL)
248 prev->next = new;
249 else
250 list->listHead = new;
251 } else
252#endif
253 {
254 new->next = (struct b_node *) NULL;
255 if (list->listTail != NULL) {
256 list->listTail->next = new;
257 list->listTail = new;
258 } else {
259 list->listTail = list->listHead = new;
260 }
261 }
262
263 return new;
264}
265
266#ifdef CFG_JFFS2_SORT_FRAGMENTS
wdenk7205e402003-09-10 22:30:53 +0000267/* Sort data entries with the latest version last, so that if there
268 * is overlapping data the latest version will be used.
269 */
wdenk06d01db2003-03-14 20:47:52 +0000270static int compare_inodes(struct b_node *new, struct b_node *old)
271{
272 struct jffs2_raw_inode *jNew = (struct jffs2_raw_inode *)new->offset;
273 struct jffs2_raw_inode *jOld = (struct jffs2_raw_inode *)old->offset;
274
wdenk7205e402003-09-10 22:30:53 +0000275 return jNew->version > jOld->version;
wdenk06d01db2003-03-14 20:47:52 +0000276}
277
wdenk7205e402003-09-10 22:30:53 +0000278/* Sort directory entries so all entries in the same directory
279 * with the same name are grouped together, with the latest version
280 * last. This makes it easy to eliminate all but the latest version
281 * by marking the previous version dead by setting the inode to 0.
282 */
wdenk06d01db2003-03-14 20:47:52 +0000283static int compare_dirents(struct b_node *new, struct b_node *old)
284{
285 struct jffs2_raw_dirent *jNew = (struct jffs2_raw_dirent *)new->offset;
286 struct jffs2_raw_dirent *jOld = (struct jffs2_raw_dirent *)old->offset;
wdenk7205e402003-09-10 22:30:53 +0000287 int cmp;
wdenk06d01db2003-03-14 20:47:52 +0000288
wdenk7205e402003-09-10 22:30:53 +0000289 /* ascending sort by pino */
290 if (jNew->pino != jOld->pino)
291 return jNew->pino > jOld->pino;
292
293 /* pino is the same, so use ascending sort by nsize, so
294 * we don't do strncmp unless we really must.
295 */
296 if (jNew->nsize != jOld->nsize)
297 return jNew->nsize > jOld->nsize;
298
299 /* length is also the same, so use ascending sort by name
300 */
301 cmp = strncmp(jNew->name, jOld->name, jNew->nsize);
302 if (cmp != 0)
303 return cmp > 0;
304
305 /* we have duplicate names in this directory, so use ascending
306 * sort by version
307 */
308 if (jNew->version > jOld->version) {
309 /* since jNew is newer, we know jOld is not valid, so
310 * mark it with inode 0 and it will not be used
311 */
312 jOld->ino = 0;
313 return 1;
314 }
wdenk42d1f032003-10-15 23:53:47 +0000315
wdenk7205e402003-09-10 22:30:53 +0000316 return 0;
wdenk06d01db2003-03-14 20:47:52 +0000317}
318#endif
wdenkfe8c2802002-11-03 00:38:21 +0000319
320static u32
321jffs2_scan_empty(u32 start_offset, struct part_info *part)
322{
wdenk06d01db2003-03-14 20:47:52 +0000323 char *max = part->offset + part->size - sizeof(struct jffs2_raw_inode);
324 char *offset = part->offset + start_offset;
wdenkfe8c2802002-11-03 00:38:21 +0000325
wdenk06d01db2003-03-14 20:47:52 +0000326 while (offset < max && *(u32 *)offset == 0xFFFFFFFF) {
327 offset += sizeof(u32);
328 /* return if spinning is due */
329 if (((u32)offset & ((1 << SPIN_BLKSIZE)-1)) == 0) break;
wdenkfe8c2802002-11-03 00:38:21 +0000330 }
wdenk06d01db2003-03-14 20:47:52 +0000331
332 return offset - part->offset;
wdenkfe8c2802002-11-03 00:38:21 +0000333}
334
335static u32
336jffs_init_1pass_list(struct part_info *part)
337{
wdenk06d01db2003-03-14 20:47:52 +0000338 struct b_lists *pL;
wdenkfe8c2802002-11-03 00:38:21 +0000339
wdenk06d01db2003-03-14 20:47:52 +0000340 if (part->jffs2_priv != NULL) {
341 pL = (struct b_lists *)part->jffs2_priv;
342 free_nodes(&pL->frag);
343 free_nodes(&pL->dir);
344 free(pL);
345 }
346 if (NULL != (part->jffs2_priv = malloc(sizeof(struct b_lists)))) {
347 pL = (struct b_lists *)part->jffs2_priv;
348
349 memset(pL, 0, sizeof(*pL));
350#ifdef CFG_JFFS2_SORT_FRAGMENTS
351 pL->dir.listCompare = compare_dirents;
352 pL->frag.listCompare = compare_inodes;
353#endif
wdenkfe8c2802002-11-03 00:38:21 +0000354 }
355 return 0;
356}
357
358/* find the inode from the slashless name given a parent */
359static long
360jffs2_1pass_read_inode(struct b_lists *pL, u32 inode, char *dest)
361{
362 struct b_node *b;
363 struct jffs2_raw_inode *jNode;
wdenk06d01db2003-03-14 20:47:52 +0000364 u32 totalSize = 0;
wdenk7205e402003-09-10 22:30:53 +0000365 u32 latestVersion = 0;
wdenk06d01db2003-03-14 20:47:52 +0000366 char *lDest;
wdenkfe8c2802002-11-03 00:38:21 +0000367 char *src;
368 long ret;
369 int i;
370 u32 counter = 0;
wdenk7205e402003-09-10 22:30:53 +0000371#ifdef CFG_JFFS2_SORT_FRAGMENTS
372 /* Find file size before loading any data, so fragments that
373 * start past the end of file can be ignored. A fragment
374 * that is partially in the file is loaded, so extra data may
375 * be loaded up to the next 4K boundary above the file size.
376 * This shouldn't cause trouble when loading kernel images, so
377 * we will live with it.
378 */
379 for (b = pL->frag.listHead; b != NULL; b = b->next) {
380 jNode = (struct jffs2_raw_inode *) (b->offset);
381 if ((inode == jNode->ino)) {
382 /* get actual file length from the newest node */
383 if (jNode->version >= latestVersion) {
384 totalSize = jNode->isize;
385 latestVersion = jNode->version;
386 }
387 }
388 }
389#endif
wdenkfe8c2802002-11-03 00:38:21 +0000390
wdenk06d01db2003-03-14 20:47:52 +0000391 for (b = pL->frag.listHead; b != NULL; b = b->next) {
wdenkfe8c2802002-11-03 00:38:21 +0000392 jNode = (struct jffs2_raw_inode *) (b->offset);
393 if ((inode == jNode->ino)) {
wdenk06d01db2003-03-14 20:47:52 +0000394#if 0
wdenkfe8c2802002-11-03 00:38:21 +0000395 putLabeledWord("\r\n\r\nread_inode: totlen = ", jNode->totlen);
396 putLabeledWord("read_inode: inode = ", jNode->ino);
397 putLabeledWord("read_inode: version = ", jNode->version);
398 putLabeledWord("read_inode: isize = ", jNode->isize);
399 putLabeledWord("read_inode: offset = ", jNode->offset);
400 putLabeledWord("read_inode: csize = ", jNode->csize);
401 putLabeledWord("read_inode: dsize = ", jNode->dsize);
402 putLabeledWord("read_inode: compr = ", jNode->compr);
403 putLabeledWord("read_inode: usercompr = ", jNode->usercompr);
404 putLabeledWord("read_inode: flags = ", jNode->flags);
wdenkfe8c2802002-11-03 00:38:21 +0000405#endif
wdenk7205e402003-09-10 22:30:53 +0000406
407#ifndef CFG_JFFS2_SORT_FRAGMENTS
wdenk06d01db2003-03-14 20:47:52 +0000408 /* get actual file length from the newest node */
409 if (jNode->version >= latestVersion) {
wdenkfe8c2802002-11-03 00:38:21 +0000410 totalSize = jNode->isize;
wdenk06d01db2003-03-14 20:47:52 +0000411 latestVersion = jNode->version;
wdenkfe8c2802002-11-03 00:38:21 +0000412 }
wdenk7205e402003-09-10 22:30:53 +0000413#endif
wdenkfe8c2802002-11-03 00:38:21 +0000414
415 if(dest) {
416 src = ((char *) jNode) + sizeof(struct jffs2_raw_inode);
wdenk06d01db2003-03-14 20:47:52 +0000417 /* ignore data behind latest known EOF */
418 if (jNode->offset > totalSize)
419 continue;
420
wdenkfe8c2802002-11-03 00:38:21 +0000421 lDest = (char *) (dest + jNode->offset);
422#if 0
wdenk06d01db2003-03-14 20:47:52 +0000423 putLabeledWord("read_inode: src = ", src);
wdenkfe8c2802002-11-03 00:38:21 +0000424 putLabeledWord("read_inode: dest = ", lDest);
wdenkfe8c2802002-11-03 00:38:21 +0000425#endif
426 switch (jNode->compr) {
427 case JFFS2_COMPR_NONE:
wdenkfe8c2802002-11-03 00:38:21 +0000428 ret = (unsigned long) ldr_memcpy(lDest, src, jNode->dsize);
429 break;
430 case JFFS2_COMPR_ZERO:
431 ret = 0;
432 for (i = 0; i < jNode->dsize; i++)
433 *(lDest++) = 0;
434 break;
435 case JFFS2_COMPR_RTIME:
436 ret = 0;
437 rtime_decompress(src, lDest, jNode->csize, jNode->dsize);
438 break;
439 case JFFS2_COMPR_DYNRUBIN:
440 /* this is slow but it works */
441 ret = 0;
442 dynrubin_decompress(src, lDest, jNode->csize, jNode->dsize);
443 break;
444 case JFFS2_COMPR_ZLIB:
445 ret = zlib_decompress(src, lDest, jNode->csize, jNode->dsize);
446 break;
447 default:
448 /* unknown */
449 putLabeledWord("UNKOWN COMPRESSION METHOD = ", jNode->compr);
450 return -1;
451 break;
452 }
453 }
454
wdenkfe8c2802002-11-03 00:38:21 +0000455#if 0
wdenkfe8c2802002-11-03 00:38:21 +0000456 putLabeledWord("read_inode: totalSize = ", totalSize);
457 putLabeledWord("read_inode: compr ret = ", ret);
458#endif
459 }
wdenkfe8c2802002-11-03 00:38:21 +0000460 counter++;
461 }
wdenkfe8c2802002-11-03 00:38:21 +0000462
463#if 0
wdenk06d01db2003-03-14 20:47:52 +0000464 putLabeledWord("read_inode: returning = ", totalSize);
wdenkfe8c2802002-11-03 00:38:21 +0000465#endif
wdenk06d01db2003-03-14 20:47:52 +0000466 return totalSize;
wdenkfe8c2802002-11-03 00:38:21 +0000467}
468
469/* find the inode from the slashless name given a parent */
470static u32
471jffs2_1pass_find_inode(struct b_lists * pL, const char *name, u32 pino)
472{
473 struct b_node *b;
474 struct jffs2_raw_dirent *jDir;
475 int len;
476 u32 counter;
477 u32 version = 0;
478 u32 inode = 0;
479
480 /* name is assumed slash free */
481 len = strlen(name);
482
483 counter = 0;
484 /* we need to search all and return the inode with the highest version */
wdenk06d01db2003-03-14 20:47:52 +0000485 for(b = pL->dir.listHead; b; b = b->next, counter++) {
wdenkfe8c2802002-11-03 00:38:21 +0000486 jDir = (struct jffs2_raw_dirent *) (b->offset);
wdenk06d01db2003-03-14 20:47:52 +0000487 if ((pino == jDir->pino) && (len == jDir->nsize) &&
488 (jDir->ino) && /* 0 for unlink */
wdenkfe8c2802002-11-03 00:38:21 +0000489 (!strncmp(jDir->name, name, len))) { /* a match */
wdenk7205e402003-09-10 22:30:53 +0000490 if (jDir->version < version)
491 continue;
wdenkfe8c2802002-11-03 00:38:21 +0000492
wdenk7205e402003-09-10 22:30:53 +0000493 if (jDir->version == version && inode != 0) {
494 /* I'm pretty sure this isn't legal */
wdenkfe8c2802002-11-03 00:38:21 +0000495 putstr(" ** ERROR ** ");
496 putnstr(jDir->name, jDir->nsize);
497 putLabeledWord(" has dup version =", version);
498 }
499 inode = jDir->ino;
500 version = jDir->version;
501 }
502#if 0
503 putstr("\r\nfind_inode:p&l ->");
504 putnstr(jDir->name, jDir->nsize);
505 putstr("\r\n");
506 putLabeledWord("pino = ", jDir->pino);
507 putLabeledWord("nsize = ", jDir->nsize);
508 putLabeledWord("b = ", (u32) b);
509 putLabeledWord("counter = ", counter);
510#endif
511 }
512 return inode;
513}
514
wdenk180d3f72004-01-04 16:28:35 +0000515char *mkmodestr(unsigned long mode, char *str)
wdenkfe8c2802002-11-03 00:38:21 +0000516{
wdenk06d01db2003-03-14 20:47:52 +0000517 static const char *l = "xwr";
518 int mask = 1, i;
519 char c;
wdenkfe8c2802002-11-03 00:38:21 +0000520
wdenk06d01db2003-03-14 20:47:52 +0000521 switch (mode & S_IFMT) {
522 case S_IFDIR: str[0] = 'd'; break;
523 case S_IFBLK: str[0] = 'b'; break;
524 case S_IFCHR: str[0] = 'c'; break;
525 case S_IFIFO: str[0] = 'f'; break;
526 case S_IFLNK: str[0] = 'l'; break;
527 case S_IFSOCK: str[0] = 's'; break;
528 case S_IFREG: str[0] = '-'; break;
529 default: str[0] = '?';
530 }
wdenkfe8c2802002-11-03 00:38:21 +0000531
wdenk06d01db2003-03-14 20:47:52 +0000532 for(i = 0; i < 9; i++) {
533 c = l[i%3];
534 str[9-i] = (mode & mask)?c:'-';
535 mask = mask<<1;
536 }
wdenkfe8c2802002-11-03 00:38:21 +0000537
wdenk06d01db2003-03-14 20:47:52 +0000538 if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
539 if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
540 if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
541 str[10] = '\0';
542 return str;
wdenkfe8c2802002-11-03 00:38:21 +0000543}
544
545static inline void dump_stat(struct stat *st, const char *name)
546{
wdenk06d01db2003-03-14 20:47:52 +0000547 char str[20];
548 char s[64], *p;
wdenkfe8c2802002-11-03 00:38:21 +0000549
wdenk06d01db2003-03-14 20:47:52 +0000550 if (st->st_mtime == (time_t)(-1)) /* some ctimes really hate -1 */
551 st->st_mtime = 1;
wdenkfe8c2802002-11-03 00:38:21 +0000552
wdenk06d01db2003-03-14 20:47:52 +0000553 ctime_r(&st->st_mtime, s/*,64*/); /* newlib ctime doesn't have buflen */
wdenkfe8c2802002-11-03 00:38:21 +0000554
wdenk06d01db2003-03-14 20:47:52 +0000555 if ((p = strchr(s,'\n')) != NULL) *p = '\0';
556 if ((p = strchr(s,'\r')) != NULL) *p = '\0';
wdenkfe8c2802002-11-03 00:38:21 +0000557
558/*
wdenk06d01db2003-03-14 20:47:52 +0000559 printf("%6lo %s %8ld %s %s\n", st->st_mode, mkmodestr(st->st_mode, str),
560 st->st_size, s, name);
wdenkfe8c2802002-11-03 00:38:21 +0000561*/
562
wdenk06d01db2003-03-14 20:47:52 +0000563 printf(" %s %8ld %s %s", mkmodestr(st->st_mode,str), st->st_size, s, name);
wdenkfe8c2802002-11-03 00:38:21 +0000564}
565
566static inline u32 dump_inode(struct b_lists * pL, struct jffs2_raw_dirent *d, struct jffs2_raw_inode *i)
567{
568 char fname[256];
569 struct stat st;
570
571 if(!d || !i) return -1;
572
573 strncpy(fname, d->name, d->nsize);
wdenk06d01db2003-03-14 20:47:52 +0000574 fname[d->nsize] = '\0';
wdenkfe8c2802002-11-03 00:38:21 +0000575
576 memset(&st,0,sizeof(st));
577
wdenk06d01db2003-03-14 20:47:52 +0000578 st.st_mtime = i->mtime;
579 st.st_mode = i->mode;
580 st.st_ino = i->ino;
wdenkfe8c2802002-11-03 00:38:21 +0000581
582 /* neither dsize nor isize help us.. do it the long way */
wdenk06d01db2003-03-14 20:47:52 +0000583 st.st_size = jffs2_1pass_read_inode(pL, i->ino, NULL);
wdenkfe8c2802002-11-03 00:38:21 +0000584
585 dump_stat(&st, fname);
586
587 if (d->type == DT_LNK) {
588 unsigned char *src = (unsigned char *) (&i[1]);
589 putstr(" -> ");
590 putnstr(src, (int)i->dsize);
591 }
592
593 putstr("\r\n");
594
595 return 0;
596}
597
598/* list inodes with the given pino */
599static u32
600jffs2_1pass_list_inodes(struct b_lists * pL, u32 pino)
601{
602 struct b_node *b;
603 struct jffs2_raw_dirent *jDir;
604
wdenk06d01db2003-03-14 20:47:52 +0000605 for (b = pL->dir.listHead; b; b = b->next) {
wdenkfe8c2802002-11-03 00:38:21 +0000606 jDir = (struct jffs2_raw_dirent *) (b->offset);
wdenk06d01db2003-03-14 20:47:52 +0000607 if ((pino == jDir->pino) && (jDir->ino)) { /* ino=0 -> unlink */
608 u32 i_version = 0;
609 struct jffs2_raw_inode *jNode, *i = NULL;
610 struct b_node *b2 = pL->frag.listHead;
wdenkfe8c2802002-11-03 00:38:21 +0000611
612 while (b2) {
613 jNode = (struct jffs2_raw_inode *) (b2->offset);
614 if (jNode->ino == jDir->ino
wdenk06d01db2003-03-14 20:47:52 +0000615 && jNode->version >= i_version)
616 i = jNode;
wdenkfe8c2802002-11-03 00:38:21 +0000617 b2 = b2->next;
618 }
619
620 dump_inode(pL, jDir, i);
621 }
622 }
623 return pino;
624}
625
626static u32
627jffs2_1pass_search_inode(struct b_lists * pL, const char *fname, u32 pino)
628{
629 int i;
630 char tmp[256];
631 char working_tmp[256];
632 char *c;
633
634 /* discard any leading slash */
635 i = 0;
636 while (fname[i] == '/')
637 i++;
638 strcpy(tmp, &fname[i]);
639
640 while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
641 {
642 strncpy(working_tmp, tmp, c - tmp);
643 working_tmp[c - tmp] = '\0';
644#if 0
645 putstr("search_inode: tmp = ");
646 putstr(tmp);
647 putstr("\r\n");
648 putstr("search_inode: wtmp = ");
649 putstr(working_tmp);
650 putstr("\r\n");
651 putstr("search_inode: c = ");
652 putstr(c);
653 putstr("\r\n");
654#endif
655 for (i = 0; i < strlen(c) - 1; i++)
656 tmp[i] = c[i + 1];
657 tmp[i] = '\0';
658#if 0
659 putstr("search_inode: post tmp = ");
660 putstr(tmp);
661 putstr("\r\n");
662#endif
663
664 if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino))) {
665 putstr("find_inode failed for name=");
666 putstr(working_tmp);
667 putstr("\r\n");
668 return 0;
669 }
670 }
671 /* this is for the bare filename, directories have already been mapped */
672 if (!(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
673 putstr("find_inode failed for name=");
674 putstr(tmp);
675 putstr("\r\n");
676 return 0;
677 }
678 return pino;
679
680}
681
682static u32
683jffs2_1pass_resolve_inode(struct b_lists * pL, u32 ino)
684{
685 struct b_node *b;
686 struct b_node *b2;
687 struct jffs2_raw_dirent *jDir;
688 struct jffs2_raw_inode *jNode;
689 struct jffs2_raw_dirent *jDirFound = NULL;
690 char tmp[256];
691 u32 version = 0;
692 u32 pino;
693 unsigned char *src;
694
695 /* we need to search all and return the inode with the highest version */
wdenk06d01db2003-03-14 20:47:52 +0000696 for(b = pL->dir.listHead; b; b = b->next) {
wdenkfe8c2802002-11-03 00:38:21 +0000697 jDir = (struct jffs2_raw_dirent *) (b->offset);
698 if (ino == jDir->ino) {
wdenk7205e402003-09-10 22:30:53 +0000699 if (jDir->version < version)
700 continue;
wdenkfe8c2802002-11-03 00:38:21 +0000701
wdenk7205e402003-09-10 22:30:53 +0000702 if (jDir->version == version && jDirFound) {
703 /* I'm pretty sure this isn't legal */
wdenkfe8c2802002-11-03 00:38:21 +0000704 putstr(" ** ERROR ** ");
705 putnstr(jDir->name, jDir->nsize);
706 putLabeledWord(" has dup version (resolve) = ",
707 version);
708 }
709
710 jDirFound = jDir;
711 version = jDir->version;
712 }
713 }
714 /* now we found the right entry again. (shoulda returned inode*) */
715 if (jDirFound->type != DT_LNK)
716 return jDirFound->ino;
wdenk06d01db2003-03-14 20:47:52 +0000717
718 /* it's a soft link so we follow it again. */
719 b2 = pL->frag.listHead;
wdenkfe8c2802002-11-03 00:38:21 +0000720 while (b2) {
721 jNode = (struct jffs2_raw_inode *) (b2->offset);
722 if (jNode->ino == jDirFound->ino) {
723 src = (unsigned char *) (b2->offset + sizeof(struct jffs2_raw_inode));
724
725#if 0
726 putLabeledWord("\t\t dsize = ", jNode->dsize);
727 putstr("\t\t target = ");
728 putnstr(src, jNode->dsize);
729 putstr("\r\n");
730#endif
731 strncpy(tmp, src, jNode->dsize);
732 tmp[jNode->dsize] = '\0';
733 break;
734 }
735 b2 = b2->next;
736 }
737 /* ok so the name of the new file to find is in tmp */
738 /* if it starts with a slash it is root based else shared dirs */
739 if (tmp[0] == '/')
740 pino = 1;
741 else
742 pino = jDirFound->pino;
743
744 return jffs2_1pass_search_inode(pL, tmp, pino);
745}
746
747static u32
748jffs2_1pass_search_list_inodes(struct b_lists * pL, const char *fname, u32 pino)
749{
750 int i;
751 char tmp[256];
752 char working_tmp[256];
753 char *c;
754
755 /* discard any leading slash */
756 i = 0;
757 while (fname[i] == '/')
758 i++;
759 strcpy(tmp, &fname[i]);
760 working_tmp[0] = '\0';
761 while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
762 {
763 strncpy(working_tmp, tmp, c - tmp);
764 working_tmp[c - tmp] = '\0';
765 for (i = 0; i < strlen(c) - 1; i++)
766 tmp[i] = c[i + 1];
767 tmp[i] = '\0';
768 /* only a failure if we arent looking at top level */
wdenk06d01db2003-03-14 20:47:52 +0000769 if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino)) &&
770 (working_tmp[0])) {
wdenkfe8c2802002-11-03 00:38:21 +0000771 putstr("find_inode failed for name=");
772 putstr(working_tmp);
773 putstr("\r\n");
774 return 0;
775 }
776 }
777
778 if (tmp[0] && !(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
779 putstr("find_inode failed for name=");
780 putstr(tmp);
781 putstr("\r\n");
782 return 0;
783 }
784 /* this is for the bare filename, directories have already been mapped */
785 if (!(pino = jffs2_1pass_list_inodes(pL, pino))) {
786 putstr("find_inode failed for name=");
787 putstr(tmp);
788 putstr("\r\n");
789 return 0;
790 }
791 return pino;
792
793}
794
795unsigned char
796jffs2_1pass_rescan_needed(struct part_info *part)
797{
798 struct b_node *b;
799 struct jffs2_unknown_node *node;
wdenk06d01db2003-03-14 20:47:52 +0000800 struct b_lists *pL = (struct b_lists *)part->jffs2_priv;
wdenkfe8c2802002-11-03 00:38:21 +0000801
802 if (part->jffs2_priv == 0){
803 DEBUGF ("rescan: First time in use\n");
804 return 1;
805 }
806 /* if we have no list, we need to rescan */
wdenk06d01db2003-03-14 20:47:52 +0000807 if (pL->frag.listCount == 0) {
wdenkfe8c2802002-11-03 00:38:21 +0000808 DEBUGF ("rescan: fraglist zero\n");
809 return 1;
810 }
811
wdenk06d01db2003-03-14 20:47:52 +0000812 /* or if we are scanning a new partition */
wdenkfe8c2802002-11-03 00:38:21 +0000813 if (pL->partOffset != part->offset) {
814 DEBUGF ("rescan: different partition\n");
815 return 1;
816 }
wdenk06d01db2003-03-14 20:47:52 +0000817 /* but suppose someone reflashed a partition at the same offset... */
818 b = pL->dir.listHead;
wdenkfe8c2802002-11-03 00:38:21 +0000819 while (b) {
820 node = (struct jffs2_unknown_node *) (b->offset);
821 if (node->nodetype != JFFS2_NODETYPE_DIRENT) {
wdenk06d01db2003-03-14 20:47:52 +0000822 DEBUGF ("rescan: fs changed beneath me? (%lx)\n",
823 (unsigned long) b->offset);
wdenkfe8c2802002-11-03 00:38:21 +0000824 return 1;
825 }
826 b = b->next;
827 }
828 return 0;
829}
830
wdenk06d01db2003-03-14 20:47:52 +0000831#ifdef DEBUG_FRAGMENTS
832static void
833dump_fragments(struct b_lists *pL)
834{
835 struct b_node *b;
836 struct jffs2_raw_inode *jNode;
837
838 putstr("\r\n\r\n******The fragment Entries******\r\n");
839 b = pL->frag.listHead;
840 while (b) {
841 jNode = (struct jffs2_raw_inode *) (b->offset);
842 putLabeledWord("\r\n\tbuild_list: FLASH_OFFSET = ", b->offset);
843 putLabeledWord("\tbuild_list: totlen = ", jNode->totlen);
844 putLabeledWord("\tbuild_list: inode = ", jNode->ino);
845 putLabeledWord("\tbuild_list: version = ", jNode->version);
846 putLabeledWord("\tbuild_list: isize = ", jNode->isize);
847 putLabeledWord("\tbuild_list: atime = ", jNode->atime);
848 putLabeledWord("\tbuild_list: offset = ", jNode->offset);
849 putLabeledWord("\tbuild_list: csize = ", jNode->csize);
850 putLabeledWord("\tbuild_list: dsize = ", jNode->dsize);
851 putLabeledWord("\tbuild_list: compr = ", jNode->compr);
852 putLabeledWord("\tbuild_list: usercompr = ", jNode->usercompr);
853 putLabeledWord("\tbuild_list: flags = ", jNode->flags);
wdenk8bde7f72003-06-27 21:31:46 +0000854 putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
wdenk06d01db2003-03-14 20:47:52 +0000855 b = b->next;
856 }
857}
858#endif
859
860#ifdef DEBUG_DIRENTS
861static void
862dump_dirents(struct b_lists *pL)
863{
864 struct b_node *b;
865 struct jffs2_raw_dirent *jDir;
866
867 putstr("\r\n\r\n******The directory Entries******\r\n");
868 b = pL->dir.listHead;
869 while (b) {
870 jDir = (struct jffs2_raw_dirent *) (b->offset);
871 putstr("\r\n");
872 putnstr(jDir->name, jDir->nsize);
873 putLabeledWord("\r\n\tbuild_list: magic = ", jDir->magic);
874 putLabeledWord("\tbuild_list: nodetype = ", jDir->nodetype);
875 putLabeledWord("\tbuild_list: hdr_crc = ", jDir->hdr_crc);
876 putLabeledWord("\tbuild_list: pino = ", jDir->pino);
877 putLabeledWord("\tbuild_list: version = ", jDir->version);
878 putLabeledWord("\tbuild_list: ino = ", jDir->ino);
879 putLabeledWord("\tbuild_list: mctime = ", jDir->mctime);
880 putLabeledWord("\tbuild_list: nsize = ", jDir->nsize);
881 putLabeledWord("\tbuild_list: type = ", jDir->type);
882 putLabeledWord("\tbuild_list: node_crc = ", jDir->node_crc);
883 putLabeledWord("\tbuild_list: name_crc = ", jDir->name_crc);
wdenk8bde7f72003-06-27 21:31:46 +0000884 putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
wdenk06d01db2003-03-14 20:47:52 +0000885 b = b->next;
886 }
887}
888#endif
889
wdenkfe8c2802002-11-03 00:38:21 +0000890static u32
891jffs2_1pass_build_lists(struct part_info * part)
892{
893 struct b_lists *pL;
894 struct jffs2_unknown_node *node;
wdenk06d01db2003-03-14 20:47:52 +0000895 u32 offset, oldoffset = 0;
wdenkfe8c2802002-11-03 00:38:21 +0000896 u32 max = part->size - sizeof(struct jffs2_raw_inode);
897 u32 counter = 0;
898 u32 counter4 = 0;
899 u32 counterF = 0;
900 u32 counterN = 0;
901
902 /* turn off the lcd. Refreshing the lcd adds 50% overhead to the */
903 /* jffs2 list building enterprise nope. in newer versions the overhead is */
904 /* only about 5 %. not enough to inconvenience people for. */
905 /* lcd_off(); */
906
907 /* if we are building a list we need to refresh the cache. */
wdenkfe8c2802002-11-03 00:38:21 +0000908 jffs_init_1pass_list(part);
wdenk06d01db2003-03-14 20:47:52 +0000909 pL = (struct b_lists *)part->jffs2_priv;
wdenkfe8c2802002-11-03 00:38:21 +0000910 pL->partOffset = part->offset;
911 offset = 0;
wdenk4b9206e2004-03-23 22:14:11 +0000912 puts ("Scanning JFFS2 FS: ");
wdenkfe8c2802002-11-03 00:38:21 +0000913
914 /* start at the beginning of the partition */
915 while (offset < max) {
wdenk06d01db2003-03-14 20:47:52 +0000916 if ((oldoffset >> SPIN_BLKSIZE) != (offset >> SPIN_BLKSIZE)) {
917 printf("\b\b%c ", spinner[counter++ % sizeof(spinner)]);
918 oldoffset = offset;
919 }
wdenkfe8c2802002-11-03 00:38:21 +0000920
921 node = (struct jffs2_unknown_node *) (part->offset + offset);
922 if (node->magic == JFFS2_MAGIC_BITMASK && hdr_crc(node)) {
923 /* if its a fragment add it */
wdenk06d01db2003-03-14 20:47:52 +0000924 if (node->nodetype == JFFS2_NODETYPE_INODE &&
925 inode_crc((struct jffs2_raw_inode *) node)) {
926 if (insert_node(&pL->frag, (u32) part->offset +
927 offset) == NULL)
wdenkfe8c2802002-11-03 00:38:21 +0000928 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000929 } else if (node->nodetype == JFFS2_NODETYPE_DIRENT &&
930 dirent_crc((struct jffs2_raw_dirent *) node) &&
931 dirent_name_crc((struct jffs2_raw_dirent *) node)) {
932 if (! (counterN%100))
wdenk4b9206e2004-03-23 22:14:11 +0000933 puts ("\b\b. ");
wdenk06d01db2003-03-14 20:47:52 +0000934 if (insert_node(&pL->dir, (u32) part->offset +
935 offset) == NULL)
wdenkfe8c2802002-11-03 00:38:21 +0000936 return 0;
wdenkfe8c2802002-11-03 00:38:21 +0000937 counterN++;
938 } else if (node->nodetype == JFFS2_NODETYPE_CLEANMARKER) {
939 if (node->totlen != sizeof(struct jffs2_unknown_node))
wdenk06d01db2003-03-14 20:47:52 +0000940 printf("OOPS Cleanmarker has bad size "
941 "%d != %d\n", node->totlen,
942 sizeof(struct jffs2_unknown_node));
wdenk7205e402003-09-10 22:30:53 +0000943 } else if (node->nodetype == JFFS2_NODETYPE_PADDING) {
944 if (node->totlen < sizeof(struct jffs2_unknown_node))
945 printf("OOPS Padding has bad size "
946 "%d < %d\n", node->totlen,
947 sizeof(struct jffs2_unknown_node));
wdenkfe8c2802002-11-03 00:38:21 +0000948 } else {
wdenk06d01db2003-03-14 20:47:52 +0000949 printf("Unknown node type: %x len %d "
950 "offset 0x%x\n", node->nodetype,
951 node->totlen, offset);
wdenkfe8c2802002-11-03 00:38:21 +0000952 }
953 offset += ((node->totlen + 3) & ~3);
954 counterF++;
wdenk06d01db2003-03-14 20:47:52 +0000955 } else if (node->magic == JFFS2_EMPTY_BITMASK &&
956 node->nodetype == JFFS2_EMPTY_BITMASK) {
wdenkfe8c2802002-11-03 00:38:21 +0000957 offset = jffs2_scan_empty(offset, part);
wdenk06d01db2003-03-14 20:47:52 +0000958 } else { /* if we know nothing, we just step and look. */
wdenkfe8c2802002-11-03 00:38:21 +0000959 offset += 4;
960 counter4++;
961 }
962/* printf("unknown node magic %4.4x %4.4x @ %lx\n", node->magic, node->nodetype, (unsigned long)node); */
963
964 }
965
966 putstr("\b\b done.\r\n"); /* close off the dots */
967 /* turn the lcd back on. */
968 /* splash(); */
969
970#if 0
wdenk06d01db2003-03-14 20:47:52 +0000971 putLabeledWord("dir entries = ", pL->dir.listCount);
972 putLabeledWord("frag entries = ", pL->frag.listCount);
wdenkfe8c2802002-11-03 00:38:21 +0000973 putLabeledWord("+4 increments = ", counter4);
974 putLabeledWord("+file_offset increments = ", counterF);
975
976#endif
977
wdenk06d01db2003-03-14 20:47:52 +0000978#ifdef DEBUG_DIRENTS
979 dump_dirents(pL);
980#endif
wdenkfe8c2802002-11-03 00:38:21 +0000981
wdenk06d01db2003-03-14 20:47:52 +0000982#ifdef DEBUG_FRAGMENTS
983 dump_fragments(pL);
984#endif
wdenkfe8c2802002-11-03 00:38:21 +0000985
wdenkfe8c2802002-11-03 00:38:21 +0000986 /* give visual feedback that we are done scanning the flash */
987 led_blink(0x0, 0x0, 0x1, 0x1); /* off, forever, on 100ms, off 100ms */
988 return 1;
989}
990
991
wdenkfe8c2802002-11-03 00:38:21 +0000992static u32
993jffs2_1pass_fill_info(struct b_lists * pL, struct b_jffs2_info * piL)
994{
995 struct b_node *b;
996 struct jffs2_raw_inode *jNode;
997 int i;
998
wdenkfe8c2802002-11-03 00:38:21 +0000999 for (i = 0; i < JFFS2_NUM_COMPR; i++) {
1000 piL->compr_info[i].num_frags = 0;
1001 piL->compr_info[i].compr_sum = 0;
1002 piL->compr_info[i].decompr_sum = 0;
1003 }
1004
wdenk06d01db2003-03-14 20:47:52 +00001005 b = pL->frag.listHead;
wdenkfe8c2802002-11-03 00:38:21 +00001006 while (b) {
1007 jNode = (struct jffs2_raw_inode *) (b->offset);
1008 if (jNode->compr < JFFS2_NUM_COMPR) {
1009 piL->compr_info[jNode->compr].num_frags++;
1010 piL->compr_info[jNode->compr].compr_sum += jNode->csize;
1011 piL->compr_info[jNode->compr].decompr_sum += jNode->dsize;
1012 }
1013 b = b->next;
1014 }
1015 return 0;
1016}
1017
1018
wdenkfe8c2802002-11-03 00:38:21 +00001019static struct b_lists *
1020jffs2_get_list(struct part_info * part, const char *who)
1021{
1022 if (jffs2_1pass_rescan_needed(part)) {
1023 if (!jffs2_1pass_build_lists(part)) {
1024 printf("%s: Failed to scan JFFSv2 file structure\n", who);
1025 return NULL;
1026 }
1027 }
1028 return (struct b_lists *)part->jffs2_priv;
1029}
1030
1031
1032/* Print directory / file contents */
1033u32
1034jffs2_1pass_ls(struct part_info * part, const char *fname)
1035{
1036 struct b_lists *pl;
1037 long ret = 0;
1038 u32 inode;
1039
wdenk06d01db2003-03-14 20:47:52 +00001040 if (! (pl = jffs2_get_list(part, "ls")))
wdenkfe8c2802002-11-03 00:38:21 +00001041 return 0;
1042
1043 if (! (inode = jffs2_1pass_search_list_inodes(pl, fname, 1))) {
1044 putstr("ls: Failed to scan jffs2 file structure\r\n");
1045 return 0;
1046 }
1047
1048
1049#if 0
1050 putLabeledWord("found file at inode = ", inode);
1051 putLabeledWord("read_inode returns = ", ret);
1052#endif
1053
1054 return ret;
1055}
1056
1057
wdenkfe8c2802002-11-03 00:38:21 +00001058/* Load a file from flash into memory. fname can be a full path */
1059u32
1060jffs2_1pass_load(char *dest, struct part_info * part, const char *fname)
1061{
1062
1063 struct b_lists *pl;
1064 long ret = 0;
1065 u32 inode;
1066
1067 if (! (pl = jffs2_get_list(part, "load")))
1068 return 0;
1069
1070 if (! (inode = jffs2_1pass_search_inode(pl, fname, 1))) {
1071 putstr("load: Failed to find inode\r\n");
1072 return 0;
1073 }
1074
1075 /* Resolve symlinks */
1076 if (! (inode = jffs2_1pass_resolve_inode(pl, inode))) {
1077 putstr("load: Failed to resolve inode structure\r\n");
1078 return 0;
1079 }
1080
1081 if ((ret = jffs2_1pass_read_inode(pl, inode, dest)) < 0) {
1082 putstr("load: Failed to read inode\r\n");
1083 return 0;
1084 }
1085
1086 DEBUGF ("load: loaded '%s' to 0x%lx (%ld bytes)\n", fname,
1087 (unsigned long) dest, ret);
1088 return ret;
1089}
1090
1091/* Return information about the fs on this partition */
1092u32
1093jffs2_1pass_info(struct part_info * part)
1094{
1095 struct b_jffs2_info info;
1096 struct b_lists *pl;
1097 int i;
1098
1099 if (! (pl = jffs2_get_list(part, "info")))
1100 return 0;
1101
1102 jffs2_1pass_fill_info(pl, &info);
wdenk06d01db2003-03-14 20:47:52 +00001103 for (i = 0; i < JFFS2_NUM_COMPR; i++) {
wdenk4b9206e2004-03-23 22:14:11 +00001104 printf ("Compression: %s\n"
1105 "\tfrag count: %d\n"
1106 "\tcompressed sum: %d\n"
1107 "\tuncompressed sum: %d\n",
1108 compr_names[i],
1109 info.compr_info[i].num_frags,
1110 info.compr_info[i].compr_sum,
1111 info.compr_info[i].decompr_sum);
wdenkfe8c2802002-11-03 00:38:21 +00001112 }
1113 return 1;
1114}
1115
1116#endif /* CFG_CMD_JFFS2 */