4 #include <linux/stat.h>
5 #include <linux/time.h>
7 #include <jffs2/jffs2.h>
8 #include <jffs2/jffs2_1pass.h>
11 #include "jffs2_nand_private.h"
13 #define NODE_CHUNK 1024 /* size of memory allocation chunk in b_nodes */
15 /* Debugging switches */
16 #undef DEBUG_DIRENTS /* print directory entry list after scan */
17 #undef DEBUG_FRAGMENTS /* print fragment list after scan */
18 #undef DEBUG /* enable debugging messages */
21 # define DEBUGF(fmt,args...) printf(fmt ,##args)
23 # define DEBUGF(fmt,args...)
26 static nand_info_t *nand;
28 /* Compression names */
29 static char *compr_names[] = {
37 #if defined(CONFIG_JFFS2_LZO_LZARI)
44 static char spinner[] = { '|', '/', '-', '\\' };
46 /* Memory management */
49 struct mem_block *next;
54 free_nodes(struct b_list *list)
56 while (list->listMemBase != NULL) {
57 struct mem_block *next = list->listMemBase->next;
58 free(list->listMemBase);
59 list->listMemBase = next;
63 static struct b_node *
64 add_node(struct b_list *list, int size)
67 struct mem_block *memBase;
70 memBase = list->listMemBase;
72 index = memBase->index;
74 if (memBase == NULL || index >= NODE_CHUNK) {
75 /* we need more space before we continue */
76 memBase = mmalloc(sizeof(struct mem_block) + NODE_CHUNK * size);
77 if (memBase == NULL) {
78 putstr("add_node: malloc failed\n");
81 memBase->next = list->listMemBase;
84 /* now we have room to add it. */
85 b = (struct b_node *)&memBase->nodes[size * index];
88 memBase->index = index;
89 list->listMemBase = memBase;
94 static struct b_node *
95 insert_node(struct b_list *list, struct b_node *new)
97 #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
98 struct b_node *b, *prev;
100 if (list->listTail != NULL && list->listCompare(new, list->listTail))
101 prev = list->listTail;
102 else if (list->listLast != NULL && list->listCompare(new, list->listLast))
103 prev = list->listLast;
107 for (b = (prev ? prev->next : list->listHead);
108 b != NULL && list->listCompare(new, b);
109 prev = b, b = b->next) {
113 list->listLast = prev;
120 list->listHead = new;
124 new->next = (struct b_node *) NULL;
125 if (list->listTail != NULL) {
126 list->listTail->next = new;
127 list->listTail = new;
129 list->listTail = list->listHead = new;
136 static struct b_node *
137 insert_inode(struct b_list *list, struct jffs2_raw_inode *node, u32 offset)
141 if (!(new = (struct b_inode *)add_node(list, sizeof(struct b_inode)))) {
142 putstr("add_node failed!\r\n");
145 new->offset = offset;
146 new->version = node->version;
147 new->ino = node->ino;
148 new->isize = node->isize;
149 new->csize = node->csize;
151 return insert_node(list, (struct b_node *)new);
154 static struct b_node *
155 insert_dirent(struct b_list *list, struct jffs2_raw_dirent *node, u32 offset)
157 struct b_dirent *new;
159 if (!(new = (struct b_dirent *)add_node(list, sizeof(struct b_dirent)))) {
160 putstr("add_node failed!\r\n");
163 new->offset = offset;
164 new->version = node->version;
165 new->pino = node->pino;
166 new->ino = node->ino;
167 new->nhash = full_name_hash(node->name, node->nsize);
168 new->nsize = node->nsize;
169 new->type = node->type;
171 return insert_node(list, (struct b_node *)new);
174 #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
175 /* Sort data entries with the latest version last, so that if there
176 * is overlapping data the latest version will be used.
178 static int compare_inodes(struct b_node *new, struct b_node *old)
180 struct jffs2_raw_inode ojNew;
181 struct jffs2_raw_inode ojOld;
182 struct jffs2_raw_inode *jNew =
183 (struct jffs2_raw_inode *)get_fl_mem(new->offset, sizeof(ojNew), &ojNew);
184 struct jffs2_raw_inode *jOld =
185 (struct jffs2_raw_inode *)get_fl_mem(old->offset, sizeof(ojOld), &ojOld);
187 return jNew->version > jOld->version;
190 /* Sort directory entries so all entries in the same directory
191 * with the same name are grouped together, with the latest version
192 * last. This makes it easy to eliminate all but the latest version
193 * by marking the previous version dead by setting the inode to 0.
195 static int compare_dirents(struct b_node *new, struct b_node *old)
197 struct jffs2_raw_dirent ojNew;
198 struct jffs2_raw_dirent ojOld;
199 struct jffs2_raw_dirent *jNew =
200 (struct jffs2_raw_dirent *)get_fl_mem(new->offset, sizeof(ojNew), &ojNew);
201 struct jffs2_raw_dirent *jOld =
202 (struct jffs2_raw_dirent *)get_fl_mem(old->offset, sizeof(ojOld), &ojOld);
205 /* ascending sort by pino */
206 if (jNew->pino != jOld->pino)
207 return jNew->pino > jOld->pino;
209 /* pino is the same, so use ascending sort by nsize, so
210 * we don't do strncmp unless we really must.
212 if (jNew->nsize != jOld->nsize)
213 return jNew->nsize > jOld->nsize;
215 /* length is also the same, so use ascending sort by name
217 cmp = strncmp(jNew->name, jOld->name, jNew->nsize);
221 /* we have duplicate names in this directory, so use ascending
224 if (jNew->version > jOld->version) {
225 /* since jNew is newer, we know jOld is not valid, so
226 * mark it with inode 0 and it will not be used
237 jffs_init_1pass_list(struct part_info *part)
241 if (part->jffs2_priv != NULL) {
242 pL = (struct b_lists *)part->jffs2_priv;
243 free_nodes(&pL->frag);
244 free_nodes(&pL->dir);
247 if (NULL != (part->jffs2_priv = malloc(sizeof(struct b_lists)))) {
248 pL = (struct b_lists *)part->jffs2_priv;
250 memset(pL, 0, sizeof(*pL));
251 #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
252 pL->dir.listCompare = compare_dirents;
253 pL->frag.listCompare = compare_inodes;
259 /* find the inode from the slashless name given a parent */
261 jffs2_1pass_read_inode(struct b_lists *pL, u32 ino, char *dest,
264 struct b_inode *jNode;
266 u32 latestVersion = 0;
269 #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
270 /* Find file size before loading any data, so fragments that
271 * start past the end of file can be ignored. A fragment
272 * that is partially in the file is loaded, so extra data may
273 * be loaded up to the next 4K boundary above the file size.
274 * This shouldn't cause trouble when loading kernel images, so
275 * we will live with it.
277 for (jNode = (struct b_inode *)pL->frag.listHead; jNode; jNode = jNode->next) {
278 if ((ino == jNode->ino)) {
279 /* get actual file length from the newest node */
280 if (jNode->version >= latestVersion) {
281 totalSize = jNode->isize;
282 latestVersion = jNode->version;
288 for (jNode = (struct b_inode *)pL->frag.listHead; jNode; jNode = jNode->next) {
289 if ((ino != jNode->ino))
291 #ifndef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
292 /* get actual file length from the newest node */
293 if (jNode->version >= latestVersion) {
294 totalSize = jNode->isize;
295 latestVersion = jNode->version;
300 char data[4096 + sizeof(struct jffs2_raw_inode)];
301 struct jffs2_raw_inode *inode;
304 inode = (struct jffs2_raw_inode *)&data;
305 len = sizeof(struct jffs2_raw_inode);
308 nand_read(nand, jNode->offset, &len, inode);
309 /* ignore data behind latest known EOF */
310 if (inode->offset > totalSize)
314 stat->st_mtime = inode->mtime;
315 stat->st_mode = inode->mode;
316 stat->st_ino = inode->ino;
317 stat->st_size = totalSize;
323 src = ((char *) inode) + sizeof(struct jffs2_raw_inode);
324 dst = (char *) (dest + inode->offset);
326 switch (inode->compr) {
327 case JFFS2_COMPR_NONE:
329 memcpy(dst, src, inode->dsize);
331 case JFFS2_COMPR_ZERO:
333 memset(dst, 0, inode->dsize);
335 case JFFS2_COMPR_RTIME:
337 rtime_decompress(src, dst, inode->csize, inode->dsize);
339 case JFFS2_COMPR_DYNRUBIN:
340 /* this is slow but it works */
342 dynrubin_decompress(src, dst, inode->csize, inode->dsize);
344 case JFFS2_COMPR_ZLIB:
345 ret = zlib_decompress(src, dst, inode->csize, inode->dsize);
347 #if defined(CONFIG_JFFS2_LZO_LZARI)
348 case JFFS2_COMPR_LZO:
349 ret = lzo_decompress(src, dst, inode->csize, inode->dsize);
351 case JFFS2_COMPR_LZARI:
352 ret = lzari_decompress(src, dst, inode->csize, inode->dsize);
357 putLabeledWord("UNKOWN COMPRESSION METHOD = ", inode->compr);
366 /* find the inode from the slashless name given a parent */
368 jffs2_1pass_find_inode(struct b_lists * pL, const char *name, u32 pino)
370 struct b_dirent *jDir;
371 int len = strlen(name); /* name is assumed slash free */
372 unsigned int nhash = full_name_hash(name, len);
376 /* we need to search all and return the inode with the highest version */
377 for (jDir = (struct b_dirent *)pL->dir.listHead; jDir; jDir = jDir->next) {
378 if ((pino == jDir->pino) && (jDir->ino) && /* 0 for unlink */
379 (len == jDir->nsize) && (nhash == jDir->nhash)) {
380 /* TODO: compare name */
381 if (jDir->version < version)
384 if (jDir->version == version && inode != 0) {
385 /* I'm pretty sure this isn't legal */
386 putstr(" ** ERROR ** ");
387 /* putnstr(jDir->name, jDir->nsize); */
388 /* putLabeledWord(" has dup version =", version); */
391 version = jDir->version;
397 char *mkmodestr(unsigned long mode, char *str)
399 static const char *l = "xwr";
403 switch (mode & S_IFMT) {
404 case S_IFDIR: str[0] = 'd'; break;
405 case S_IFBLK: str[0] = 'b'; break;
406 case S_IFCHR: str[0] = 'c'; break;
407 case S_IFIFO: str[0] = 'f'; break;
408 case S_IFLNK: str[0] = 'l'; break;
409 case S_IFSOCK: str[0] = 's'; break;
410 case S_IFREG: str[0] = '-'; break;
411 default: str[0] = '?';
414 for(i = 0; i < 9; i++) {
416 str[9-i] = (mode & mask)?c:'-';
420 if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
421 if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
422 if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
427 static inline void dump_stat(struct stat *st, const char *name)
432 if (st->st_mtime == (time_t)(-1)) /* some ctimes really hate -1 */
435 ctime_r(&st->st_mtime, s/*,64*/); /* newlib ctime doesn't have buflen */
437 if ((p = strchr(s,'\n')) != NULL) *p = '\0';
438 if ((p = strchr(s,'\r')) != NULL) *p = '\0';
441 printf("%6lo %s %8ld %s %s\n", st->st_mode, mkmodestr(st->st_mode, str),
442 st->st_size, s, name);
445 printf(" %s %8ld %s %s", mkmodestr(st->st_mode,str), st->st_size, s, name);
449 dump_inode(struct b_lists *pL, struct b_dirent *d, struct b_inode *i)
451 char fname[JFFS2_MAX_NAME_LEN + 1];
455 if(!d || !i) return -1;
457 nand_read(nand, d->offset + sizeof(struct jffs2_raw_dirent),
459 fname[d->nsize] = '\0';
461 memset(&st, 0, sizeof(st));
463 jffs2_1pass_read_inode(pL, i->ino, NULL, &st);
465 dump_stat(&st, fname);
467 if (d->type == DT_LNK) {
468 unsigned char *src = (unsigned char *) (&i[1]);
470 putnstr(src, (int)i->dsize);
478 /* list inodes with the given pino */
480 jffs2_1pass_list_inodes(struct b_lists * pL, u32 pino)
482 struct b_dirent *jDir;
485 for (jDir = (struct b_dirent *)pL->dir.listHead; jDir; jDir = jDir->next) {
486 if ((pino == jDir->pino) && (jDir->ino)) { /* ino=0 -> unlink */
487 struct b_inode *jNode = (struct b_inode *)pL->frag.listHead;
488 struct b_inode *i = NULL;
491 if (jNode->ino == jDir->ino && jNode->version >= i_version) {
492 i_version = jNode->version;
497 dump_inode(pL, jDir, i);
504 jffs2_1pass_search_inode(struct b_lists * pL, const char *fname, u32 pino)
508 char working_tmp[256];
511 /* discard any leading slash */
513 while (fname[i] == '/')
515 strcpy(tmp, &fname[i]);
517 while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
519 strncpy(working_tmp, tmp, c - tmp);
520 working_tmp[c - tmp] = '\0';
522 putstr("search_inode: tmp = ");
525 putstr("search_inode: wtmp = ");
528 putstr("search_inode: c = ");
532 for (i = 0; i < strlen(c) - 1; i++)
536 putstr("search_inode: post tmp = ");
541 if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino))) {
542 putstr("find_inode failed for name=");
548 /* this is for the bare filename, directories have already been mapped */
549 if (!(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
550 putstr("find_inode failed for name=");
560 jffs2_1pass_resolve_inode(struct b_lists * pL, u32 ino)
562 struct b_dirent *jDir;
563 struct b_inode *jNode;
564 u8 jDirFoundType = 0;
565 u32 jDirFoundIno = 0;
566 u32 jDirFoundPino = 0;
567 char tmp[JFFS2_MAX_NAME_LEN + 1];
571 /* we need to search all and return the inode with the highest version */
572 for (jDir = (struct b_dirent *)pL->dir.listHead; jDir; jDir = jDir->next) {
573 if (ino == jDir->ino) {
574 if (jDir->version < version)
577 if (jDir->version == version && jDirFoundType) {
578 /* I'm pretty sure this isn't legal */
579 putstr(" ** ERROR ** ");
580 /* putnstr(jDir->name, jDir->nsize); */
581 /* putLabeledWord(" has dup version (resolve) = ", */
585 jDirFoundType = jDir->type;
586 jDirFoundIno = jDir->ino;
587 jDirFoundPino = jDir->pino;
588 version = jDir->version;
591 /* now we found the right entry again. (shoulda returned inode*) */
592 if (jDirFoundType != DT_LNK)
595 /* it's a soft link so we follow it again. */
596 for (jNode = (struct b_inode *)pL->frag.listHead; jNode; jNode = jNode->next) {
597 if (jNode->ino == jDirFoundIno) {
598 size_t len = jNode->csize;
599 nand_read(nand, jNode->offset + sizeof(struct jffs2_raw_inode), &len, &tmp);
600 tmp[jNode->csize] = '\0';
604 /* ok so the name of the new file to find is in tmp */
605 /* if it starts with a slash it is root based else shared dirs */
609 pino = jDirFoundPino;
611 return jffs2_1pass_search_inode(pL, tmp, pino);
615 jffs2_1pass_search_list_inodes(struct b_lists * pL, const char *fname, u32 pino)
619 char working_tmp[256];
622 /* discard any leading slash */
624 while (fname[i] == '/')
626 strcpy(tmp, &fname[i]);
627 working_tmp[0] = '\0';
628 while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
630 strncpy(working_tmp, tmp, c - tmp);
631 working_tmp[c - tmp] = '\0';
632 for (i = 0; i < strlen(c) - 1; i++)
635 /* only a failure if we arent looking at top level */
636 if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino)) &&
638 putstr("find_inode failed for name=");
645 if (tmp[0] && !(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
646 putstr("find_inode failed for name=");
651 /* this is for the bare filename, directories have already been mapped */
652 if (!(pino = jffs2_1pass_list_inodes(pL, pino))) {
653 putstr("find_inode failed for name=");
663 jffs2_1pass_rescan_needed(struct part_info *part)
666 struct jffs2_unknown_node onode;
667 struct jffs2_unknown_node *node;
668 struct b_lists *pL = (struct b_lists *)part->jffs2_priv;
670 if (part->jffs2_priv == 0){
671 DEBUGF ("rescan: First time in use\n");
674 /* if we have no list, we need to rescan */
675 if (pL->frag.listCount == 0) {
676 DEBUGF ("rescan: fraglist zero\n");
680 /* or if we are scanning a new partition */
681 if (pL->partOffset != part->offset) {
682 DEBUGF ("rescan: different partition\n");
688 /* but suppose someone reflashed a partition at the same offset... */
689 b = pL->dir.listHead;
691 node = (struct jffs2_unknown_node *) get_fl_mem(b->offset,
692 sizeof(onode), &onode);
693 if (node->nodetype != JFFS2_NODETYPE_DIRENT) {
694 DEBUGF ("rescan: fs changed beneath me? (%lx)\n",
695 (unsigned long) b->offset);
704 #ifdef DEBUG_FRAGMENTS
706 dump_fragments(struct b_lists *pL)
709 struct jffs2_raw_inode ojNode;
710 struct jffs2_raw_inode *jNode;
712 putstr("\r\n\r\n******The fragment Entries******\r\n");
713 b = pL->frag.listHead;
715 jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
716 sizeof(ojNode), &ojNode);
717 putLabeledWord("\r\n\tbuild_list: FLASH_OFFSET = ", b->offset);
718 putLabeledWord("\tbuild_list: totlen = ", jNode->totlen);
719 putLabeledWord("\tbuild_list: inode = ", jNode->ino);
720 putLabeledWord("\tbuild_list: version = ", jNode->version);
721 putLabeledWord("\tbuild_list: isize = ", jNode->isize);
722 putLabeledWord("\tbuild_list: atime = ", jNode->atime);
723 putLabeledWord("\tbuild_list: offset = ", jNode->offset);
724 putLabeledWord("\tbuild_list: csize = ", jNode->csize);
725 putLabeledWord("\tbuild_list: dsize = ", jNode->dsize);
726 putLabeledWord("\tbuild_list: compr = ", jNode->compr);
727 putLabeledWord("\tbuild_list: usercompr = ", jNode->usercompr);
728 putLabeledWord("\tbuild_list: flags = ", jNode->flags);
729 putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
737 dump_dirents(struct b_lists *pL)
740 struct jffs2_raw_dirent *jDir;
742 putstr("\r\n\r\n******The directory Entries******\r\n");
743 b = pL->dir.listHead;
745 jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset);
747 putnstr(jDir->name, jDir->nsize);
748 putLabeledWord("\r\n\tbuild_list: magic = ", jDir->magic);
749 putLabeledWord("\tbuild_list: nodetype = ", jDir->nodetype);
750 putLabeledWord("\tbuild_list: hdr_crc = ", jDir->hdr_crc);
751 putLabeledWord("\tbuild_list: pino = ", jDir->pino);
752 putLabeledWord("\tbuild_list: version = ", jDir->version);
753 putLabeledWord("\tbuild_list: ino = ", jDir->ino);
754 putLabeledWord("\tbuild_list: mctime = ", jDir->mctime);
755 putLabeledWord("\tbuild_list: nsize = ", jDir->nsize);
756 putLabeledWord("\tbuild_list: type = ", jDir->type);
757 putLabeledWord("\tbuild_list: node_crc = ", jDir->node_crc);
758 putLabeledWord("\tbuild_list: name_crc = ", jDir->name_crc);
759 putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
767 jffs2_fill_scan_buf(nand_info_t *nand, unsigned char *buf,
768 unsigned ofs, unsigned len)
774 ret = nand_read(nand, ofs, &olen, buf);
776 printf("nand_read(0x%x bytes from 0x%x) returned %d\n", len, ofs, ret);
780 printf("Read at 0x%x gave only 0x%x bytes\n", ofs, olen);
786 #define EMPTY_SCAN_SIZE 1024
788 jffs2_1pass_build_lists(struct part_info * part)
791 struct jffs2_unknown_node *node;
792 unsigned nr_blocks, sectorsize, ofs, offset;
800 struct mtdids *id = part->dev->id;
801 nand = nand_info + id->num;
803 /* if we are building a list we need to refresh the cache. */
804 jffs_init_1pass_list(part);
805 pL = (struct b_lists *)part->jffs2_priv;
806 pL->partOffset = part->offset;
807 puts ("Scanning JFFS2 FS: ");
809 sectorsize = nand->erasesize;
810 nr_blocks = part->size / sectorsize;
811 buf = malloc(sectorsize);
815 for (i = 0; i < nr_blocks; i++) {
816 printf("\b\b%c ", spinner[counter++ % sizeof(spinner)]);
818 offset = part->offset + i * sectorsize;
820 if (nand_block_isbad(nand, offset))
823 if (jffs2_fill_scan_buf(nand, buf, offset, EMPTY_SCAN_SIZE))
827 /* Scan only 4KiB of 0xFF before declaring it's empty */
828 while (ofs < EMPTY_SCAN_SIZE && *(uint32_t *)(&buf[ofs]) == 0xFFFFFFFF)
830 if (ofs == EMPTY_SCAN_SIZE)
833 if (jffs2_fill_scan_buf(nand, buf + EMPTY_SCAN_SIZE, offset + EMPTY_SCAN_SIZE, sectorsize - EMPTY_SCAN_SIZE))
837 while (ofs < sectorsize - sizeof(struct jffs2_unknown_node)) {
838 node = (struct jffs2_unknown_node *)&buf[ofs];
839 if (node->magic != JFFS2_MAGIC_BITMASK || !hdr_crc(node)) {
845 /* if its a fragment add it */
846 if (node->nodetype == JFFS2_NODETYPE_INODE &&
847 inode_crc((struct jffs2_raw_inode *) node)) {
848 if (insert_inode(&pL->frag, (struct jffs2_raw_inode *) node,
852 } else if (node->nodetype == JFFS2_NODETYPE_DIRENT &&
853 dirent_crc((struct jffs2_raw_dirent *) node) &&
854 dirent_name_crc((struct jffs2_raw_dirent *) node)) {
855 if (! (counterN%100))
857 if (insert_dirent(&pL->dir, (struct jffs2_raw_dirent *) node,
862 } else if (node->nodetype == JFFS2_NODETYPE_CLEANMARKER) {
863 if (node->totlen != sizeof(struct jffs2_unknown_node))
864 printf("OOPS Cleanmarker has bad size "
867 sizeof(struct jffs2_unknown_node));
868 } else if (node->nodetype == JFFS2_NODETYPE_PADDING) {
869 if (node->totlen < sizeof(struct jffs2_unknown_node))
870 printf("OOPS Padding has bad size "
873 sizeof(struct jffs2_unknown_node));
875 printf("Unknown node type: %x len %d offset 0x%x\n",
877 node->totlen, offset);
879 offset += ((node->totlen + 3) & ~3);
880 ofs += ((node->totlen + 3) & ~3);
885 putstr("\b\b done.\r\n"); /* close off the dots */
888 putLabeledWord("dir entries = ", pL->dir.listCount);
889 putLabeledWord("frag entries = ", pL->frag.listCount);
890 putLabeledWord("+4 increments = ", counter4);
891 putLabeledWord("+file_offset increments = ", counterF);
898 #ifdef DEBUG_FRAGMENTS
902 /* give visual feedback that we are done scanning the flash */
903 led_blink(0x0, 0x0, 0x1, 0x1); /* off, forever, on 100ms, off 100ms */
911 jffs2_1pass_fill_info(struct b_lists * pL, struct b_jffs2_info * piL)
914 struct jffs2_raw_inode ojNode;
915 struct jffs2_raw_inode *jNode;
918 for (i = 0; i < JFFS2_NUM_COMPR; i++) {
919 piL->compr_info[i].num_frags = 0;
920 piL->compr_info[i].compr_sum = 0;
921 piL->compr_info[i].decompr_sum = 0;
924 b = pL->frag.listHead;
926 jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
927 sizeof(ojNode), &ojNode);
928 if (jNode->compr < JFFS2_NUM_COMPR) {
929 piL->compr_info[jNode->compr].num_frags++;
930 piL->compr_info[jNode->compr].compr_sum += jNode->csize;
931 piL->compr_info[jNode->compr].decompr_sum += jNode->dsize;
940 static struct b_lists *
941 jffs2_get_list(struct part_info * part, const char *who)
943 if (jffs2_1pass_rescan_needed(part)) {
944 if (!jffs2_1pass_build_lists(part)) {
945 printf("%s: Failed to scan JFFSv2 file structure\n", who);
949 return (struct b_lists *)part->jffs2_priv;
953 /* Print directory / file contents */
955 jffs2_1pass_ls(struct part_info * part, const char *fname)
961 if (! (pl = jffs2_get_list(part, "ls")))
964 if (! (inode = jffs2_1pass_search_list_inodes(pl, fname, 1))) {
965 putstr("ls: Failed to scan jffs2 file structure\r\n");
970 putLabeledWord("found file at inode = ", inode);
971 putLabeledWord("read_inode returns = ", ret);
978 /* Load a file from flash into memory. fname can be a full path */
980 jffs2_1pass_load(char *dest, struct part_info * part, const char *fname)
987 if (! (pl = jffs2_get_list(part, "load")))
990 if (! (inode = jffs2_1pass_search_inode(pl, fname, 1))) {
991 putstr("load: Failed to find inode\r\n");
995 /* Resolve symlinks */
996 if (! (inode = jffs2_1pass_resolve_inode(pl, inode))) {
997 putstr("load: Failed to resolve inode structure\r\n");
1001 if ((ret = jffs2_1pass_read_inode(pl, inode, dest, NULL)) < 0) {
1002 putstr("load: Failed to read inode\r\n");
1006 DEBUGF ("load: loaded '%s' to 0x%lx (%ld bytes)\n", fname,
1007 (unsigned long) dest, ret);
1011 /* Return information about the fs on this partition */
1013 jffs2_1pass_info(struct part_info * part)
1015 struct b_jffs2_info info;
1019 if (! (pl = jffs2_get_list(part, "info")))
1022 jffs2_1pass_fill_info(pl, &info);
1023 for (i = 0; i < JFFS2_NUM_COMPR; i++) {
1024 printf ("Compression: %s\n"
1025 "\tfrag count: %d\n"
1026 "\tcompressed sum: %d\n"
1027 "\tuncompressed sum: %d\n",
1029 info.compr_info[i].num_frags,
1030 info.compr_info[i].compr_sum,
1031 info.compr_info[i].decompr_sum);