2 -------------------------------------------------------------------------
4 * Version: $Id: jffs2_1pass.c,v 1.7 2002/01/25 01:56:47 nyet Exp $
5 * Copyright: Copyright (C) 2001, Russ Dill
7 * Description: Module to load kernel from jffs2
8 *-----------------------------------------------------------------------*/
10 * some portions of this code are taken from jffs2, and as such, the
11 * following copyright notice is included.
13 * JFFS2 -- Journalling Flash File System, Version 2.
15 * Copyright (C) 2001 Red Hat, Inc.
19 * The original JFFS, from which the design for JFFS2 was derived,
20 * was designed and implemented by Axis Communications AB.
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/
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.
32 * The Original Code is JFFS2 - Journalling Flash File System, version 2
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.
45 * $Id: jffs2_1pass.c,v 1.7 2002/01/25 01:56:47 nyet Exp $
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
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
69 * on Jan/2002 for U-Boot.
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 ;).
81 #include <linux/stat.h>
82 #include <linux/time.h>
84 #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
86 #include <jffs2/jffs2.h>
87 #include <jffs2/jffs2_1pass.h>
89 #include "jffs2_private.h"
91 /* Compression names */
92 static char *compr_names[] = {
101 static char spinner[] = { '|', '\\', '-', '/' };
105 # define DEBUGF(fmt,args...) printf(fmt ,##args)
107 # define DEBUGF(fmt,args...)
110 #define MALLOC_CHUNK (10*1024)
113 static struct b_node *
114 add_node(struct b_node *tail, u32 * count, u32 * memBase)
120 index = (*count) * sizeof(struct b_node) % MALLOC_CHUNK;
121 memLimit = MALLOC_CHUNK;
124 putLabeledWord("add_node: index = ", index);
125 putLabeledWord("add_node: memLimit = ", memLimit);
126 putLabeledWord("add_node: memBase = ", *memBase);
129 /* we need not keep a list of bases since we'll never free the */
130 /* memory, just jump the the kernel */
131 if ((index == 0) || (index > memLimit)) { /* we need mode space before we continue */
132 if ((*memBase = (u32) mmalloc(MALLOC_CHUNK)) == (u32) NULL) {
133 putstr("add_node: malloc failed\n");
137 putLabeledWord("add_node: alloced a new membase at ", *memBase);
141 /* now we have room to add it. */
142 b = (struct b_node *) (*memBase + index);
144 /* null on first call */
149 putLabeledWord("add_node: tail = ", (u32) tail);
151 putLabeledWord("add_node: tail->next = ", (u32) tail->next);
156 putLabeledWord("add_node: mb+i = ", (u32) (*memBase + index));
157 putLabeledWord("add_node: b = ", (u32) b);
160 b->next = (struct b_node *) NULL;
165 /* we know we have empties at the start offset so we will hop */
166 /* t points that would be non F if there were a node here to speed this up. */
167 struct jffs2_empty_node {
173 jffs2_scan_empty(u32 start_offset, struct part_info *part)
175 u32 max = part->size - sizeof(struct jffs2_raw_inode);
177 /* this would be either dir node_crc or frag isize */
178 u32 offset = start_offset + 32;
179 struct jffs2_empty_node *node;
182 while (offset < max) {
183 node = (struct jffs2_empty_node *) (part->offset + offset);
184 if ((node->first == 0xFFFFFFFF) && (node->second == 0xFFFFFFFF)) {
185 /* we presume that there were no nodes in between and advance in a hop */
186 /* putLabeledWord("\t\tjffs2_scan_empty: empty at offset=",offset); */
187 start_offset = offset + 4;
188 offset = start_offset + 32; /* orig 32 + 4 bytes for the second==0xfffff */
197 jffs_init_1pass_list(struct part_info *part)
199 if ( 0 != ( part->jffs2_priv=malloc(sizeof(struct b_lists)))){
200 struct b_lists *pL =(struct b_lists *)part->jffs2_priv;
202 pL->dirListHead = pL->dirListTail = NULL;
203 pL->fragListHead = pL->fragListTail = NULL;
204 pL->dirListCount = 0;
205 pL->dirListMemBase = 0;
206 pL->fragListCount = 0;
207 pL->fragListMemBase = 0;
208 pL->partOffset = 0x0;
213 /* find the inode from the slashless name given a parent */
215 jffs2_1pass_read_inode(struct b_lists *pL, u32 inode, char *dest)
218 struct jffs2_raw_inode *jNode;
220 u32 oldTotalSize = 0;
222 char *lDest = (char *) dest;
227 char totalSizeSet = 0;
230 b = pL->fragListHead;
232 jNode = (struct jffs2_raw_inode *) (b->offset);
233 if ((inode == jNode->ino)) {
234 putLabeledWord("\r\n\r\nread_inode: totlen = ", jNode->totlen);
235 putLabeledWord("read_inode: inode = ", jNode->ino);
236 putLabeledWord("read_inode: version = ", jNode->version);
237 putLabeledWord("read_inode: isize = ", jNode->isize);
238 putLabeledWord("read_inode: offset = ", jNode->offset);
239 putLabeledWord("read_inode: csize = ", jNode->csize);
240 putLabeledWord("read_inode: dsize = ", jNode->dsize);
241 putLabeledWord("read_inode: compr = ", jNode->compr);
242 putLabeledWord("read_inode: usercompr = ", jNode->usercompr);
243 putLabeledWord("read_inode: flags = ", jNode->flags);
252 b = pL->fragListHead;
253 while (b && (size < totalSize)) {
254 jNode = (struct jffs2_raw_inode *) (b->offset);
255 if ((inode == jNode->ino)) {
256 if ((jNode->isize == oldTotalSize) && (jNode->isize > totalSize)) {
257 /* 2 consecutive isizes indicate file length */
258 totalSize = jNode->isize;
260 } else if (!totalSizeSet) {
261 totalSize = size + jNode->dsize + 1;
263 oldTotalSize = jNode->isize;
266 src = ((char *) jNode) + sizeof(struct jffs2_raw_inode);
267 /* lDest = (char *) (dest + (jNode->offset & ~3)); */
268 lDest = (char *) (dest + jNode->offset);
270 putLabeledWord("\r\n\r\nread_inode: src = ", src);
271 putLabeledWord("read_inode: dest = ", lDest);
272 putLabeledWord("read_inode: dsize = ", jNode->dsize);
273 putLabeledWord("read_inode: csize = ", jNode->csize);
274 putLabeledWord("read_inode: version = ", jNode->version);
275 putLabeledWord("read_inode: isize = ", jNode->isize);
276 putLabeledWord("read_inode: offset = ", jNode->offset);
277 putLabeledWord("read_inode: compr = ", jNode->compr);
278 putLabeledWord("read_inode: flags = ", jNode->flags);
280 switch (jNode->compr) {
281 case JFFS2_COMPR_NONE:
286 if ((dest > 0xc0092ff0) && (dest < 0xc0093000))
287 for (i = 0; i < first->length; i++) {
288 putLabeledWord("\tCOMPR_NONE: src =", src + i);
289 putLabeledWord("\tCOMPR_NONE: length =", first->length);
290 putLabeledWord("\tCOMPR_NONE: dest =", dest + i);
291 putLabeledWord("\tCOMPR_NONE: data =", (unsigned char) *(src + i));
296 ret = (unsigned long) ldr_memcpy(lDest, src, jNode->dsize);
298 case JFFS2_COMPR_ZERO:
300 for (i = 0; i < jNode->dsize; i++)
303 case JFFS2_COMPR_RTIME:
305 rtime_decompress(src, lDest, jNode->csize, jNode->dsize);
307 case JFFS2_COMPR_DYNRUBIN:
308 /* this is slow but it works */
310 dynrubin_decompress(src, lDest, jNode->csize, jNode->dsize);
312 case JFFS2_COMPR_ZLIB:
313 ret = zlib_decompress(src, lDest, jNode->csize, jNode->dsize);
317 putLabeledWord("UNKOWN COMPRESSION METHOD = ", jNode->compr);
323 size += jNode->dsize;
325 putLabeledWord("read_inode: size = ", size);
326 putLabeledWord("read_inode: totalSize = ", totalSize);
327 putLabeledWord("read_inode: compr ret = ", ret);
336 putLabeledWord("read_inode: returning = ", size);
341 /* find the inode from the slashless name given a parent */
343 jffs2_1pass_find_inode(struct b_lists * pL, const char *name, u32 pino)
346 struct jffs2_raw_dirent *jDir;
352 /* name is assumed slash free */
356 /* we need to search all and return the inode with the highest version */
357 for(b = pL->dirListHead;b;b=b->next,counter++) {
358 jDir = (struct jffs2_raw_dirent *) (b->offset);
359 if ((pino == jDir->pino) && (len == jDir->nsize) && (jDir->ino) && /* 0 for unlink */
360 (!strncmp(jDir->name, name, len))) { /* a match */
361 if (jDir->version < version) continue;
363 if(jDir->version==0) {
365 putstr(" ** WARNING ** ");
366 putnstr(jDir->name, jDir->nsize);
367 putstr(" is version 0 (in find, ignoring)\r\n");
368 } else if(jDir->version==version) {
369 /* Im pretty sure this isn't ... */
370 putstr(" ** ERROR ** ");
371 putnstr(jDir->name, jDir->nsize);
372 putLabeledWord(" has dup version =", version);
375 version = jDir->version;
378 putstr("\r\nfind_inode:p&l ->");
379 putnstr(jDir->name, jDir->nsize);
381 putLabeledWord("pino = ", jDir->pino);
382 putLabeledWord("nsize = ", jDir->nsize);
383 putLabeledWord("b = ", (u32) b);
384 putLabeledWord("counter = ", counter);
390 static char *mkmodestr(unsigned long mode, char *str)
392 static const char *l="xwr";
396 switch (mode & S_IFMT) {
397 case S_IFDIR: str[0]='d'; break;
398 case S_IFBLK: str[0]='b'; break;
399 case S_IFCHR: str[0]='c'; break;
400 case S_IFIFO: str[0]='f'; break;
401 case S_IFLNK: str[0]='l'; break;
402 case S_IFSOCK: str[0]='s'; break;
403 case S_IFREG: str[0]='-'; break;
409 str[9-i]=(mode & mask)?c:'-';
413 if(mode & S_ISUID) str[3]=(mode & S_IXUSR)?'s':'S';
414 if(mode & S_ISGID) str[6]=(mode & S_IXGRP)?'s':'S';
415 if(mode & S_ISVTX) str[9]=(mode & S_IXOTH)?'t':'T';
420 static inline void dump_stat(struct stat *st, const char *name)
425 if (st->st_mtime == (time_t)(-1)) /* some ctimes really hate -1 */
428 ctime_r(&st->st_mtime, s/*, 64*/); /* newlib ctime doesn't have buflen */
430 if((p=strchr(s,'\n'))!=NULL) *p='\0';
431 if((p=strchr(s,'\r'))!=NULL) *p='\0';
434 printf("%6lo %s %8ld %s %s\n", st->st_mode, mkmodestr(st->st_mode, str),
435 st->st_size, s, name);
438 printf(" %s %8ld %s %s", mkmodestr(st->st_mode,str), st->st_size, s, name);
441 static inline u32 dump_inode(struct b_lists * pL, struct jffs2_raw_dirent *d, struct jffs2_raw_inode *i)
446 if(!d || !i) return -1;
448 strncpy(fname, d->name, d->nsize);
449 fname[d->nsize]='\0';
451 memset(&st,0,sizeof(st));
453 st.st_mtime=i->mtime;
457 /* neither dsize nor isize help us.. do it the long way */
458 st.st_size=jffs2_1pass_read_inode(pL, i->ino, NULL);
460 dump_stat(&st, fname);
462 if (d->type == DT_LNK) {
463 unsigned char *src = (unsigned char *) (&i[1]);
465 putnstr(src, (int)i->dsize);
473 /* list inodes with the given pino */
475 jffs2_1pass_list_inodes(struct b_lists * pL, u32 pino)
478 struct jffs2_raw_dirent *jDir;
480 for(b = pL->dirListHead;b;b=b->next) {
481 jDir = (struct jffs2_raw_dirent *) (b->offset);
482 if ((pino == jDir->pino) && (jDir->ino)) { /* 0 inode for unlink */
484 struct jffs2_raw_inode *jNode, *i=NULL;
485 struct b_node *b2 = pL->fragListHead;
488 jNode = (struct jffs2_raw_inode *) (b2->offset);
489 if (jNode->ino == jDir->ino
490 && jNode->version>=i_version)
495 dump_inode(pL, jDir, i);
502 jffs2_1pass_search_inode(struct b_lists * pL, const char *fname, u32 pino)
506 char working_tmp[256];
509 /* discard any leading slash */
511 while (fname[i] == '/')
513 strcpy(tmp, &fname[i]);
515 while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
517 strncpy(working_tmp, tmp, c - tmp);
518 working_tmp[c - tmp] = '\0';
520 putstr("search_inode: tmp = ");
523 putstr("search_inode: wtmp = ");
526 putstr("search_inode: c = ");
530 for (i = 0; i < strlen(c) - 1; i++)
534 putstr("search_inode: post tmp = ");
539 if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino))) {
540 putstr("find_inode failed for name=");
546 /* this is for the bare filename, directories have already been mapped */
547 if (!(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
548 putstr("find_inode failed for name=");
558 jffs2_1pass_resolve_inode(struct b_lists * pL, u32 ino)
562 struct jffs2_raw_dirent *jDir;
563 struct jffs2_raw_inode *jNode;
564 struct jffs2_raw_dirent *jDirFound = NULL;
570 /* we need to search all and return the inode with the highest version */
571 for(b = pL->dirListHead; b; b=b->next) {
572 jDir = (struct jffs2_raw_dirent *) (b->offset);
573 if (ino == jDir->ino) {
574 if(jDir->version < version) continue;
576 if(jDir->version == 0) {
578 putstr(" ** WARNING ** ");
579 putnstr(jDir->name, jDir->nsize);
580 putstr(" is version 0 (in resolve, ignoring)\r\n");
581 } else if(jDir->version == version) {
582 /* Im pretty sure this isn't ... */
583 putstr(" ** ERROR ** ");
584 putnstr(jDir->name, jDir->nsize);
585 putLabeledWord(" has dup version (resolve) = ",
590 version = jDir->version;
593 /* now we found the right entry again. (shoulda returned inode*) */
594 if (jDirFound->type != DT_LNK)
595 return jDirFound->ino;
596 /* so its a soft link so we follow it again. */
597 b2 = pL->fragListHead;
599 jNode = (struct jffs2_raw_inode *) (b2->offset);
600 if (jNode->ino == jDirFound->ino) {
601 src = (unsigned char *) (b2->offset + sizeof(struct jffs2_raw_inode));
604 putLabeledWord("\t\t dsize = ", jNode->dsize);
605 putstr("\t\t target = ");
606 putnstr(src, jNode->dsize);
609 strncpy(tmp, src, jNode->dsize);
610 tmp[jNode->dsize] = '\0';
615 /* ok so the name of the new file to find is in tmp */
616 /* if it starts with a slash it is root based else shared dirs */
620 pino = jDirFound->pino;
622 return jffs2_1pass_search_inode(pL, tmp, pino);
626 jffs2_1pass_search_list_inodes(struct b_lists * pL, const char *fname, u32 pino)
630 char working_tmp[256];
633 /* discard any leading slash */
635 while (fname[i] == '/')
637 strcpy(tmp, &fname[i]);
638 working_tmp[0] = '\0';
639 while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
641 strncpy(working_tmp, tmp, c - tmp);
642 working_tmp[c - tmp] = '\0';
643 for (i = 0; i < strlen(c) - 1; i++)
646 /* only a failure if we arent looking at top level */
647 if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino)) && (working_tmp[0])) {
648 putstr("find_inode failed for name=");
655 if (tmp[0] && !(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
656 putstr("find_inode failed for name=");
661 /* this is for the bare filename, directories have already been mapped */
662 if (!(pino = jffs2_1pass_list_inodes(pL, pino))) {
663 putstr("find_inode failed for name=");
673 jffs2_1pass_rescan_needed(struct part_info *part)
676 struct jffs2_unknown_node *node;
677 struct b_lists *pL=(struct b_lists *)part->jffs2_priv;
679 if (part->jffs2_priv == 0){
680 DEBUGF ("rescan: First time in use\n");
683 /* if we have no list, we need to rescan */
684 if (pL->fragListCount == 0) {
685 DEBUGF ("rescan: fraglist zero\n");
689 /* or if we are scanninga new partition */
690 if (pL->partOffset != part->offset) {
691 DEBUGF ("rescan: different partition\n");
694 /* but suppose someone reflashed the root partition at the same offset... */
697 node = (struct jffs2_unknown_node *) (b->offset);
698 if (node->nodetype != JFFS2_NODETYPE_DIRENT) {
699 DEBUGF ("rescan: fs changed beneath me? (%lx)\n", (unsigned long) b->offset);
708 jffs2_1pass_build_lists(struct part_info * part)
711 struct jffs2_unknown_node *node;
713 u32 max = part->size - sizeof(struct jffs2_raw_inode);
719 /* turn off the lcd. Refreshing the lcd adds 50% overhead to the */
720 /* jffs2 list building enterprise nope. in newer versions the overhead is */
721 /* only about 5 %. not enough to inconvenience people for. */
724 /* if we are building a list we need to refresh the cache. */
725 /* note that since we don't free our memory, eventually this will be bad. */
726 /* but we're a bootldr so what the hell. */
727 jffs_init_1pass_list(part);
728 pL=(struct b_lists *)part->jffs2_priv;
729 pL->partOffset = part->offset;
731 printf("Scanning JFFS2 FS: ");
733 /* start at the beginning of the partition */
734 while (offset < max) {
735 if (! (++counter%10000))
736 printf("\b\b%c ", spinner[(counter / 10000) % 4]);
738 node = (struct jffs2_unknown_node *) (part->offset + offset);
739 if (node->magic == JFFS2_MAGIC_BITMASK && hdr_crc(node)) {
740 /* if its a fragment add it */
741 if (node->nodetype == JFFS2_NODETYPE_INODE && inode_crc((struct jffs2_raw_inode *) node)) {
742 if (!(pL->fragListTail = add_node(pL->fragListTail, &(pL->fragListCount),
743 &(pL->fragListMemBase)))) {
744 putstr("add_node failed!\r\n");
747 pL->fragListTail->offset = (u32) (part->offset + offset);
748 if (!pL->fragListHead)
749 pL->fragListHead = pL->fragListTail;
750 } else if (node->nodetype == JFFS2_NODETYPE_DIRENT &&
751 dirent_crc((struct jffs2_raw_dirent *) node) &&
752 dirent_name_crc((struct jffs2_raw_dirent *) node)) {
753 if (! (counterN%100))
756 printf("Found DIRENT @ 0x%lx\n", offset);
757 putstr("\r\nbuild_lists:p&l ->");
758 putnstr(((struct jffs2_raw_dirent *) node)->name, ((struct jffs2_raw_dirent *) node)->nsize);
760 putLabeledWord("\tpino = ", ((struct jffs2_raw_dirent *) node)->pino);
761 putLabeledWord("\tnsize = ", ((struct jffs2_raw_dirent *) node)->nsize);
764 if (!(pL->dirListTail = add_node(pL->dirListTail, &(pL->dirListCount), &(pL->dirListMemBase)))) {
765 putstr("add_node failed!\r\n");
768 pL->dirListTail->offset = (u32) (part->offset + offset);
770 putLabeledWord("\ttail = ", (u32) pL->dirListTail);
771 putstr("\ttailName ->");
772 putnstr(((struct jffs2_raw_dirent *) (pL->dirListTail->offset))->name,
773 ((struct jffs2_raw_dirent *) (pL->dirListTail->offset))->nsize);
776 if (!pL->dirListHead)
777 pL->dirListHead = pL->dirListTail;
779 } else if (node->nodetype == JFFS2_NODETYPE_CLEANMARKER) {
780 if (node->totlen != sizeof(struct jffs2_unknown_node))
781 printf("OOPS Cleanmarker has bad size %d != %d\n", node->totlen, sizeof(struct jffs2_unknown_node));
783 printf("Unknown node type: %x len %d offset 0x%x\n", node->nodetype, node->totlen, offset);
785 offset += ((node->totlen + 3) & ~3);
787 } else if (node->magic == JFFS2_EMPTY_BITMASK && node->nodetype == JFFS2_EMPTY_BITMASK) {
788 offset = jffs2_scan_empty(offset, part);
789 } else { /* if we know nothing of the filesystem, we just step and look. */
793 /* printf("unknown node magic %4.4x %4.4x @ %lx\n", node->magic, node->nodetype, (unsigned long)node); */
797 putstr("\b\b done.\r\n"); /* close off the dots */
798 /* turn the lcd back on. */
802 putLabeledWord("dir entries = ", pL->dirListCount);
803 putLabeledWord("frag entries = ", pL->fragListCount);
804 putLabeledWord("+4 increments = ", counter4);
805 putLabeledWord("+file_offset increments = ", counterF);
810 #undef SHOW_ALL_FRAGMENTS
816 struct jffs2_raw_dirent *jDir;
817 struct jffs2_raw_inode *jNode;
819 putstr("\r\n\r\n******The directory Entries******\r\n");
822 jDir = (struct jffs2_raw_dirent *) (b->offset);
824 putnstr(jDir->name, jDir->nsize);
825 putLabeledWord("\r\n\tbuild_list: magic = ", jDir->magic);
826 putLabeledWord("\tbuild_list: nodetype = ", jDir->nodetype);
827 putLabeledWord("\tbuild_list: hdr_crc = ", jDir->hdr_crc);
828 putLabeledWord("\tbuild_list: pino = ", jDir->pino);
829 putLabeledWord("\tbuild_list: version = ", jDir->version);
830 putLabeledWord("\tbuild_list: ino = ", jDir->ino);
831 putLabeledWord("\tbuild_list: mctime = ", jDir->mctime);
832 putLabeledWord("\tbuild_list: nsize = ", jDir->nsize);
833 putLabeledWord("\tbuild_list: type = ", jDir->type);
834 putLabeledWord("\tbuild_list: node_crc = ", jDir->node_crc);
835 putLabeledWord("\tbuild_list: name_crc = ", jDir->name_crc);
839 #ifdef SHOW_ALL_FRAGMENTS
840 putstr("\r\n\r\n******The fragment Entries******\r\n");
841 b = pL->fragListHead;
843 jNode = (struct jffs2_raw_inode *) (b->offset);
844 putLabeledWord("\r\n\tbuild_list: FLASH_OFFSET = ", b->offset);
845 putLabeledWord("\tbuild_list: totlen = ", jNode->totlen);
846 putLabeledWord("\tbuild_list: inode = ", jNode->ino);
847 putLabeledWord("\tbuild_list: version = ", jNode->version);
848 putLabeledWord("\tbuild_list: isize = ", jNode->isize);
849 putLabeledWord("\tbuild_list: atime = ", jNode->atime);
850 putLabeledWord("\tbuild_list: offset = ", jNode->offset);
851 putLabeledWord("\tbuild_list: csize = ", jNode->csize);
852 putLabeledWord("\tbuild_list: dsize = ", jNode->dsize);
853 putLabeledWord("\tbuild_list: compr = ", jNode->compr);
854 putLabeledWord("\tbuild_list: usercompr = ", jNode->usercompr);
855 putLabeledWord("\tbuild_list: flags = ", jNode->flags);
858 #endif /* SHOW_ALL_FRAGMENTS */
861 #endif /* SHOW_ALL */
862 /* give visual feedback that we are done scanning the flash */
863 led_blink(0x0, 0x0, 0x1, 0x1); /* off, forever, on 100ms, off 100ms */
872 jffs2_1pass_fill_info(struct b_lists * pL, struct b_jffs2_info * piL)
875 struct jffs2_raw_inode *jNode;
878 b = pL->fragListHead;
879 for (i = 0; i < JFFS2_NUM_COMPR; i++) {
880 piL->compr_info[i].num_frags = 0;
881 piL->compr_info[i].compr_sum = 0;
882 piL->compr_info[i].decompr_sum = 0;
886 jNode = (struct jffs2_raw_inode *) (b->offset);
887 if (jNode->compr < JFFS2_NUM_COMPR) {
888 piL->compr_info[jNode->compr].num_frags++;
889 piL->compr_info[jNode->compr].compr_sum += jNode->csize;
890 piL->compr_info[jNode->compr].decompr_sum += jNode->dsize;
899 static struct b_lists *
900 jffs2_get_list(struct part_info * part, const char *who)
902 if (jffs2_1pass_rescan_needed(part)) {
903 if (!jffs2_1pass_build_lists(part)) {
904 printf("%s: Failed to scan JFFSv2 file structure\n", who);
908 return (struct b_lists *)part->jffs2_priv;
912 /* Print directory / file contents */
914 jffs2_1pass_ls(struct part_info * part, const char *fname)
920 if (! (pl = jffs2_get_list(part, "ls")))
923 if (! (inode = jffs2_1pass_search_list_inodes(pl, fname, 1))) {
924 putstr("ls: Failed to scan jffs2 file structure\r\n");
930 putLabeledWord("found file at inode = ", inode);
931 putLabeledWord("read_inode returns = ", ret);
941 /* Load a file from flash into memory. fname can be a full path */
943 jffs2_1pass_load(char *dest, struct part_info * part, const char *fname)
950 if (! (pl = jffs2_get_list(part, "load")))
953 if (! (inode = jffs2_1pass_search_inode(pl, fname, 1))) {
954 putstr("load: Failed to find inode\r\n");
958 /* Resolve symlinks */
959 if (! (inode = jffs2_1pass_resolve_inode(pl, inode))) {
960 putstr("load: Failed to resolve inode structure\r\n");
964 if ((ret = jffs2_1pass_read_inode(pl, inode, dest)) < 0) {
965 putstr("load: Failed to read inode\r\n");
969 DEBUGF ("load: loaded '%s' to 0x%lx (%ld bytes)\n", fname,
970 (unsigned long) dest, ret);
974 /* Return information about the fs on this partition */
976 jffs2_1pass_info(struct part_info * part)
978 struct b_jffs2_info info;
982 if (! (pl = jffs2_get_list(part, "info")))
985 jffs2_1pass_fill_info(pl, &info);
986 for (i=0; i < JFFS2_NUM_COMPR; i++) {
987 printf("Compression: %s\n", compr_names[i]);
988 printf("\tfrag count: %d\n", info.compr_info[i].num_frags);
989 printf("\tcompressed sum: %d\n", info.compr_info[i].compr_sum);
990 printf("\tuncompressed sum: %d\n", info.compr_info[i].decompr_sum);
995 #endif /* CFG_CMD_JFFS2 */