3 #if !defined(CFG_NAND_LEGACY) && defined(CONFIG_CMD_JFFS2)
6 #include <linux/stat.h>
7 #include <linux/time.h>
9 #include <jffs2/jffs2.h>
10 #include <jffs2/jffs2_1pass.h>
13 #include "jffs2_nand_private.h"
15 #define NODE_CHUNK 1024 /* size of memory allocation chunk in b_nodes */
17 /* Debugging switches */
18 #undef DEBUG_DIRENTS /* print directory entry list after scan */
19 #undef DEBUG_FRAGMENTS /* print fragment list after scan */
20 #undef DEBUG /* enable debugging messages */
23 # define DEBUGF(fmt,args...) printf(fmt ,##args)
25 # define DEBUGF(fmt,args...)
28 static nand_info_t *nand;
30 /* Compression names */
31 static char *compr_names[] = {
39 #if defined(CONFIG_JFFS2_LZO_LZARI)
46 static char spinner[] = { '|', '/', '-', '\\' };
48 /* Memory management */
51 struct mem_block *next;
56 free_nodes(struct b_list *list)
58 while (list->listMemBase != NULL) {
59 struct mem_block *next = list->listMemBase->next;
60 free(list->listMemBase);
61 list->listMemBase = next;
65 static struct b_node *
66 add_node(struct b_list *list, int size)
69 struct mem_block *memBase;
72 memBase = list->listMemBase;
74 index = memBase->index;
76 if (memBase == NULL || index >= NODE_CHUNK) {
77 /* we need more space before we continue */
78 memBase = mmalloc(sizeof(struct mem_block) + NODE_CHUNK * size);
79 if (memBase == NULL) {
80 putstr("add_node: malloc failed\n");
83 memBase->next = list->listMemBase;
86 /* now we have room to add it. */
87 b = (struct b_node *)&memBase->nodes[size * index];
90 memBase->index = index;
91 list->listMemBase = memBase;
96 static struct b_node *
97 insert_node(struct b_list *list, struct b_node *new)
99 #ifdef CFG_JFFS2_SORT_FRAGMENTS
100 struct b_node *b, *prev;
102 if (list->listTail != NULL && list->listCompare(new, list->listTail))
103 prev = list->listTail;
104 else if (list->listLast != NULL && list->listCompare(new, list->listLast))
105 prev = list->listLast;
109 for (b = (prev ? prev->next : list->listHead);
110 b != NULL && list->listCompare(new, b);
111 prev = b, b = b->next) {
115 list->listLast = prev;
122 list->listHead = new;
126 new->next = (struct b_node *) NULL;
127 if (list->listTail != NULL) {
128 list->listTail->next = new;
129 list->listTail = new;
131 list->listTail = list->listHead = new;
138 static struct b_node *
139 insert_inode(struct b_list *list, struct jffs2_raw_inode *node, u32 offset)
143 if (!(new = (struct b_inode *)add_node(list, sizeof(struct b_inode)))) {
144 putstr("add_node failed!\r\n");
147 new->offset = offset;
148 new->version = node->version;
149 new->ino = node->ino;
150 new->isize = node->isize;
151 new->csize = node->csize;
153 return insert_node(list, (struct b_node *)new);
156 static struct b_node *
157 insert_dirent(struct b_list *list, struct jffs2_raw_dirent *node, u32 offset)
159 struct b_dirent *new;
161 if (!(new = (struct b_dirent *)add_node(list, sizeof(struct b_dirent)))) {
162 putstr("add_node failed!\r\n");
165 new->offset = offset;
166 new->version = node->version;
167 new->pino = node->pino;
168 new->ino = node->ino;
169 new->nhash = full_name_hash(node->name, node->nsize);
170 new->nsize = node->nsize;
171 new->type = node->type;
173 return insert_node(list, (struct b_node *)new);
176 #ifdef CFG_JFFS2_SORT_FRAGMENTS
177 /* Sort data entries with the latest version last, so that if there
178 * is overlapping data the latest version will be used.
180 static int compare_inodes(struct b_node *new, struct b_node *old)
182 struct jffs2_raw_inode ojNew;
183 struct jffs2_raw_inode ojOld;
184 struct jffs2_raw_inode *jNew =
185 (struct jffs2_raw_inode *)get_fl_mem(new->offset, sizeof(ojNew), &ojNew);
186 struct jffs2_raw_inode *jOld =
187 (struct jffs2_raw_inode *)get_fl_mem(old->offset, sizeof(ojOld), &ojOld);
189 return jNew->version > jOld->version;
192 /* Sort directory entries so all entries in the same directory
193 * with the same name are grouped together, with the latest version
194 * last. This makes it easy to eliminate all but the latest version
195 * by marking the previous version dead by setting the inode to 0.
197 static int compare_dirents(struct b_node *new, struct b_node *old)
199 struct jffs2_raw_dirent ojNew;
200 struct jffs2_raw_dirent ojOld;
201 struct jffs2_raw_dirent *jNew =
202 (struct jffs2_raw_dirent *)get_fl_mem(new->offset, sizeof(ojNew), &ojNew);
203 struct jffs2_raw_dirent *jOld =
204 (struct jffs2_raw_dirent *)get_fl_mem(old->offset, sizeof(ojOld), &ojOld);
207 /* ascending sort by pino */
208 if (jNew->pino != jOld->pino)
209 return jNew->pino > jOld->pino;
211 /* pino is the same, so use ascending sort by nsize, so
212 * we don't do strncmp unless we really must.
214 if (jNew->nsize != jOld->nsize)
215 return jNew->nsize > jOld->nsize;
217 /* length is also the same, so use ascending sort by name
219 cmp = strncmp(jNew->name, jOld->name, jNew->nsize);
223 /* we have duplicate names in this directory, so use ascending
226 if (jNew->version > jOld->version) {
227 /* since jNew is newer, we know jOld is not valid, so
228 * mark it with inode 0 and it will not be used
239 jffs_init_1pass_list(struct part_info *part)
243 if (part->jffs2_priv != NULL) {
244 pL = (struct b_lists *)part->jffs2_priv;
245 free_nodes(&pL->frag);
246 free_nodes(&pL->dir);
249 if (NULL != (part->jffs2_priv = malloc(sizeof(struct b_lists)))) {
250 pL = (struct b_lists *)part->jffs2_priv;
252 memset(pL, 0, sizeof(*pL));
253 #ifdef CFG_JFFS2_SORT_FRAGMENTS
254 pL->dir.listCompare = compare_dirents;
255 pL->frag.listCompare = compare_inodes;
261 /* find the inode from the slashless name given a parent */
263 jffs2_1pass_read_inode(struct b_lists *pL, u32 ino, char *dest,
266 struct b_inode *jNode;
268 u32 latestVersion = 0;
271 #ifdef CFG_JFFS2_SORT_FRAGMENTS
272 /* Find file size before loading any data, so fragments that
273 * start past the end of file can be ignored. A fragment
274 * that is partially in the file is loaded, so extra data may
275 * be loaded up to the next 4K boundary above the file size.
276 * This shouldn't cause trouble when loading kernel images, so
277 * we will live with it.
279 for (jNode = (struct b_inode *)pL->frag.listHead; jNode; jNode = jNode->next) {
280 if ((ino == jNode->ino)) {
281 /* get actual file length from the newest node */
282 if (jNode->version >= latestVersion) {
283 totalSize = jNode->isize;
284 latestVersion = jNode->version;
290 for (jNode = (struct b_inode *)pL->frag.listHead; jNode; jNode = jNode->next) {
291 if ((ino != jNode->ino))
293 #ifndef CFG_JFFS2_SORT_FRAGMENTS
294 /* get actual file length from the newest node */
295 if (jNode->version >= latestVersion) {
296 totalSize = jNode->isize;
297 latestVersion = jNode->version;
302 char data[4096 + sizeof(struct jffs2_raw_inode)];
303 struct jffs2_raw_inode *inode;
306 inode = (struct jffs2_raw_inode *)&data;
307 len = sizeof(struct jffs2_raw_inode);
310 nand_read(nand, jNode->offset, &len, inode);
311 /* ignore data behind latest known EOF */
312 if (inode->offset > totalSize)
316 stat->st_mtime = inode->mtime;
317 stat->st_mode = inode->mode;
318 stat->st_ino = inode->ino;
319 stat->st_size = totalSize;
325 src = ((char *) inode) + sizeof(struct jffs2_raw_inode);
326 dst = (char *) (dest + inode->offset);
328 switch (inode->compr) {
329 case JFFS2_COMPR_NONE:
331 memcpy(dst, src, inode->dsize);
333 case JFFS2_COMPR_ZERO:
335 memset(dst, 0, inode->dsize);
337 case JFFS2_COMPR_RTIME:
339 rtime_decompress(src, dst, inode->csize, inode->dsize);
341 case JFFS2_COMPR_DYNRUBIN:
342 /* this is slow but it works */
344 dynrubin_decompress(src, dst, inode->csize, inode->dsize);
346 case JFFS2_COMPR_ZLIB:
347 ret = zlib_decompress(src, dst, inode->csize, inode->dsize);
349 #if defined(CONFIG_JFFS2_LZO_LZARI)
350 case JFFS2_COMPR_LZO:
351 ret = lzo_decompress(src, dst, inode->csize, inode->dsize);
353 case JFFS2_COMPR_LZARI:
354 ret = lzari_decompress(src, dst, inode->csize, inode->dsize);
359 putLabeledWord("UNKOWN COMPRESSION METHOD = ", inode->compr);
368 /* find the inode from the slashless name given a parent */
370 jffs2_1pass_find_inode(struct b_lists * pL, const char *name, u32 pino)
372 struct b_dirent *jDir;
373 int len = strlen(name); /* name is assumed slash free */
374 unsigned int nhash = full_name_hash(name, len);
378 /* we need to search all and return the inode with the highest version */
379 for (jDir = (struct b_dirent *)pL->dir.listHead; jDir; jDir = jDir->next) {
380 if ((pino == jDir->pino) && (jDir->ino) && /* 0 for unlink */
381 (len == jDir->nsize) && (nhash == jDir->nhash)) {
382 /* TODO: compare name */
383 if (jDir->version < version)
386 if (jDir->version == version && inode != 0) {
387 /* I'm pretty sure this isn't legal */
388 putstr(" ** ERROR ** ");
389 /* putnstr(jDir->name, jDir->nsize); */
390 /* putLabeledWord(" has dup version =", version); */
393 version = jDir->version;
399 char *mkmodestr(unsigned long mode, char *str)
401 static const char *l = "xwr";
405 switch (mode & S_IFMT) {
406 case S_IFDIR: str[0] = 'd'; break;
407 case S_IFBLK: str[0] = 'b'; break;
408 case S_IFCHR: str[0] = 'c'; break;
409 case S_IFIFO: str[0] = 'f'; break;
410 case S_IFLNK: str[0] = 'l'; break;
411 case S_IFSOCK: str[0] = 's'; break;
412 case S_IFREG: str[0] = '-'; break;
413 default: str[0] = '?';
416 for(i = 0; i < 9; i++) {
418 str[9-i] = (mode & mask)?c:'-';
422 if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
423 if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
424 if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
429 static inline void dump_stat(struct stat *st, const char *name)
434 if (st->st_mtime == (time_t)(-1)) /* some ctimes really hate -1 */
437 ctime_r(&st->st_mtime, s/*,64*/); /* newlib ctime doesn't have buflen */
439 if ((p = strchr(s,'\n')) != NULL) *p = '\0';
440 if ((p = strchr(s,'\r')) != NULL) *p = '\0';
443 printf("%6lo %s %8ld %s %s\n", st->st_mode, mkmodestr(st->st_mode, str),
444 st->st_size, s, name);
447 printf(" %s %8ld %s %s", mkmodestr(st->st_mode,str), st->st_size, s, name);
451 dump_inode(struct b_lists *pL, struct b_dirent *d, struct b_inode *i)
453 char fname[JFFS2_MAX_NAME_LEN + 1];
457 if(!d || !i) return -1;
459 nand_read(nand, d->offset + sizeof(struct jffs2_raw_dirent),
461 fname[d->nsize] = '\0';
463 memset(&st, 0, sizeof(st));
465 jffs2_1pass_read_inode(pL, i->ino, NULL, &st);
467 dump_stat(&st, fname);
469 if (d->type == DT_LNK) {
470 unsigned char *src = (unsigned char *) (&i[1]);
472 putnstr(src, (int)i->dsize);
480 /* list inodes with the given pino */
482 jffs2_1pass_list_inodes(struct b_lists * pL, u32 pino)
484 struct b_dirent *jDir;
487 for (jDir = (struct b_dirent *)pL->dir.listHead; jDir; jDir = jDir->next) {
488 if ((pino == jDir->pino) && (jDir->ino)) { /* ino=0 -> unlink */
489 struct b_inode *jNode = (struct b_inode *)pL->frag.listHead;
490 struct b_inode *i = NULL;
493 if (jNode->ino == jDir->ino && jNode->version >= i_version) {
494 i_version = jNode->version;
499 dump_inode(pL, jDir, i);
506 jffs2_1pass_search_inode(struct b_lists * pL, const char *fname, u32 pino)
510 char working_tmp[256];
513 /* discard any leading slash */
515 while (fname[i] == '/')
517 strcpy(tmp, &fname[i]);
519 while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
521 strncpy(working_tmp, tmp, c - tmp);
522 working_tmp[c - tmp] = '\0';
524 putstr("search_inode: tmp = ");
527 putstr("search_inode: wtmp = ");
530 putstr("search_inode: c = ");
534 for (i = 0; i < strlen(c) - 1; i++)
538 putstr("search_inode: post tmp = ");
543 if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino))) {
544 putstr("find_inode failed for name=");
550 /* this is for the bare filename, directories have already been mapped */
551 if (!(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
552 putstr("find_inode failed for name=");
562 jffs2_1pass_resolve_inode(struct b_lists * pL, u32 ino)
564 struct b_dirent *jDir;
565 struct b_inode *jNode;
566 u8 jDirFoundType = 0;
567 u32 jDirFoundIno = 0;
568 u32 jDirFoundPino = 0;
569 char tmp[JFFS2_MAX_NAME_LEN + 1];
573 /* we need to search all and return the inode with the highest version */
574 for (jDir = (struct b_dirent *)pL->dir.listHead; jDir; jDir = jDir->next) {
575 if (ino == jDir->ino) {
576 if (jDir->version < version)
579 if (jDir->version == version && jDirFoundType) {
580 /* I'm pretty sure this isn't legal */
581 putstr(" ** ERROR ** ");
582 /* putnstr(jDir->name, jDir->nsize); */
583 /* putLabeledWord(" has dup version (resolve) = ", */
587 jDirFoundType = jDir->type;
588 jDirFoundIno = jDir->ino;
589 jDirFoundPino = jDir->pino;
590 version = jDir->version;
593 /* now we found the right entry again. (shoulda returned inode*) */
594 if (jDirFoundType != DT_LNK)
597 /* it's a soft link so we follow it again. */
598 for (jNode = (struct b_inode *)pL->frag.listHead; jNode; jNode = jNode->next) {
599 if (jNode->ino == jDirFoundIno) {
600 size_t len = jNode->csize;
601 nand_read(nand, jNode->offset + sizeof(struct jffs2_raw_inode), &len, &tmp);
602 tmp[jNode->csize] = '\0';
606 /* ok so the name of the new file to find is in tmp */
607 /* if it starts with a slash it is root based else shared dirs */
611 pino = jDirFoundPino;
613 return jffs2_1pass_search_inode(pL, tmp, pino);
617 jffs2_1pass_search_list_inodes(struct b_lists * pL, const char *fname, u32 pino)
621 char working_tmp[256];
624 /* discard any leading slash */
626 while (fname[i] == '/')
628 strcpy(tmp, &fname[i]);
629 working_tmp[0] = '\0';
630 while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
632 strncpy(working_tmp, tmp, c - tmp);
633 working_tmp[c - tmp] = '\0';
634 for (i = 0; i < strlen(c) - 1; i++)
637 /* only a failure if we arent looking at top level */
638 if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino)) &&
640 putstr("find_inode failed for name=");
647 if (tmp[0] && !(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
648 putstr("find_inode failed for name=");
653 /* this is for the bare filename, directories have already been mapped */
654 if (!(pino = jffs2_1pass_list_inodes(pL, pino))) {
655 putstr("find_inode failed for name=");
665 jffs2_1pass_rescan_needed(struct part_info *part)
668 struct jffs2_unknown_node onode;
669 struct jffs2_unknown_node *node;
670 struct b_lists *pL = (struct b_lists *)part->jffs2_priv;
672 if (part->jffs2_priv == 0){
673 DEBUGF ("rescan: First time in use\n");
676 /* if we have no list, we need to rescan */
677 if (pL->frag.listCount == 0) {
678 DEBUGF ("rescan: fraglist zero\n");
682 /* or if we are scanning a new partition */
683 if (pL->partOffset != part->offset) {
684 DEBUGF ("rescan: different partition\n");
690 /* but suppose someone reflashed a partition at the same offset... */
691 b = pL->dir.listHead;
693 node = (struct jffs2_unknown_node *) get_fl_mem(b->offset,
694 sizeof(onode), &onode);
695 if (node->nodetype != JFFS2_NODETYPE_DIRENT) {
696 DEBUGF ("rescan: fs changed beneath me? (%lx)\n",
697 (unsigned long) b->offset);
706 #ifdef DEBUG_FRAGMENTS
708 dump_fragments(struct b_lists *pL)
711 struct jffs2_raw_inode ojNode;
712 struct jffs2_raw_inode *jNode;
714 putstr("\r\n\r\n******The fragment Entries******\r\n");
715 b = pL->frag.listHead;
717 jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
718 sizeof(ojNode), &ojNode);
719 putLabeledWord("\r\n\tbuild_list: FLASH_OFFSET = ", b->offset);
720 putLabeledWord("\tbuild_list: totlen = ", jNode->totlen);
721 putLabeledWord("\tbuild_list: inode = ", jNode->ino);
722 putLabeledWord("\tbuild_list: version = ", jNode->version);
723 putLabeledWord("\tbuild_list: isize = ", jNode->isize);
724 putLabeledWord("\tbuild_list: atime = ", jNode->atime);
725 putLabeledWord("\tbuild_list: offset = ", jNode->offset);
726 putLabeledWord("\tbuild_list: csize = ", jNode->csize);
727 putLabeledWord("\tbuild_list: dsize = ", jNode->dsize);
728 putLabeledWord("\tbuild_list: compr = ", jNode->compr);
729 putLabeledWord("\tbuild_list: usercompr = ", jNode->usercompr);
730 putLabeledWord("\tbuild_list: flags = ", jNode->flags);
731 putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
739 dump_dirents(struct b_lists *pL)
742 struct jffs2_raw_dirent *jDir;
744 putstr("\r\n\r\n******The directory Entries******\r\n");
745 b = pL->dir.listHead;
747 jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset);
749 putnstr(jDir->name, jDir->nsize);
750 putLabeledWord("\r\n\tbuild_list: magic = ", jDir->magic);
751 putLabeledWord("\tbuild_list: nodetype = ", jDir->nodetype);
752 putLabeledWord("\tbuild_list: hdr_crc = ", jDir->hdr_crc);
753 putLabeledWord("\tbuild_list: pino = ", jDir->pino);
754 putLabeledWord("\tbuild_list: version = ", jDir->version);
755 putLabeledWord("\tbuild_list: ino = ", jDir->ino);
756 putLabeledWord("\tbuild_list: mctime = ", jDir->mctime);
757 putLabeledWord("\tbuild_list: nsize = ", jDir->nsize);
758 putLabeledWord("\tbuild_list: type = ", jDir->type);
759 putLabeledWord("\tbuild_list: node_crc = ", jDir->node_crc);
760 putLabeledWord("\tbuild_list: name_crc = ", jDir->name_crc);
761 putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
769 jffs2_fill_scan_buf(nand_info_t *nand, unsigned char *buf,
770 unsigned ofs, unsigned len)
776 ret = nand_read(nand, ofs, &olen, buf);
778 printf("nand_read(0x%x bytes from 0x%x) returned %d\n", len, ofs, ret);
782 printf("Read at 0x%x gave only 0x%x bytes\n", ofs, olen);
788 #define EMPTY_SCAN_SIZE 1024
790 jffs2_1pass_build_lists(struct part_info * part)
793 struct jffs2_unknown_node *node;
794 unsigned nr_blocks, sectorsize, ofs, offset;
802 struct mtdids *id = part->dev->id;
803 nand = nand_info + id->num;
805 /* if we are building a list we need to refresh the cache. */
806 jffs_init_1pass_list(part);
807 pL = (struct b_lists *)part->jffs2_priv;
808 pL->partOffset = part->offset;
809 puts ("Scanning JFFS2 FS: ");
811 sectorsize = nand->erasesize;
812 nr_blocks = part->size / sectorsize;
813 buf = malloc(sectorsize);
817 for (i = 0; i < nr_blocks; i++) {
818 printf("\b\b%c ", spinner[counter++ % sizeof(spinner)]);
820 offset = part->offset + i * sectorsize;
822 if (nand_block_isbad(nand, offset))
825 if (jffs2_fill_scan_buf(nand, buf, offset, EMPTY_SCAN_SIZE))
829 /* Scan only 4KiB of 0xFF before declaring it's empty */
830 while (ofs < EMPTY_SCAN_SIZE && *(uint32_t *)(&buf[ofs]) == 0xFFFFFFFF)
832 if (ofs == EMPTY_SCAN_SIZE)
835 if (jffs2_fill_scan_buf(nand, buf + EMPTY_SCAN_SIZE, offset + EMPTY_SCAN_SIZE, sectorsize - EMPTY_SCAN_SIZE))
839 while (ofs < sectorsize - sizeof(struct jffs2_unknown_node)) {
840 node = (struct jffs2_unknown_node *)&buf[ofs];
841 if (node->magic != JFFS2_MAGIC_BITMASK || !hdr_crc(node)) {
847 /* if its a fragment add it */
848 if (node->nodetype == JFFS2_NODETYPE_INODE &&
849 inode_crc((struct jffs2_raw_inode *) node)) {
850 if (insert_inode(&pL->frag, (struct jffs2_raw_inode *) node,
854 } else if (node->nodetype == JFFS2_NODETYPE_DIRENT &&
855 dirent_crc((struct jffs2_raw_dirent *) node) &&
856 dirent_name_crc((struct jffs2_raw_dirent *) node)) {
857 if (! (counterN%100))
859 if (insert_dirent(&pL->dir, (struct jffs2_raw_dirent *) node,
864 } else if (node->nodetype == JFFS2_NODETYPE_CLEANMARKER) {
865 if (node->totlen != sizeof(struct jffs2_unknown_node))
866 printf("OOPS Cleanmarker has bad size "
867 "%d != %d\n", node->totlen,
868 sizeof(struct jffs2_unknown_node));
869 } else if (node->nodetype == JFFS2_NODETYPE_PADDING) {
870 if (node->totlen < sizeof(struct jffs2_unknown_node))
871 printf("OOPS Padding has bad size "
872 "%d < %d\n", node->totlen,
873 sizeof(struct jffs2_unknown_node));
875 printf("Unknown node type: %x len %d "
876 "offset 0x%x\n", node->nodetype,
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);