2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
5 * Zoltan Sogor <weth@inf.u-szeged.hu>,
6 * Patrik Kluba <pajko@halom.u-szeged.hu>,
7 * University of Szeged, Hungary
8 * 2005 KaiGai Kohei <kaigai@ak.jp.nec.com>
10 * For licensing information, see the file 'LICENCE' in this directory.
12 * $Id: summary.c,v 1.4 2005/09/26 11:37:21 havasi Exp $
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/slab.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/pagemap.h>
21 #include <linux/crc32.h>
22 #include <linux/compiler.h>
23 #include <linux/vmalloc.h>
27 int jffs2_sum_init(struct jffs2_sb_info *c)
29 c->summary = kmalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
32 JFFS2_WARNING("Can't allocate memory for summary information!\n");
36 memset(c->summary, 0, sizeof(struct jffs2_summary));
38 c->summary->sum_buf = vmalloc(c->sector_size);
40 if (!c->summary->sum_buf) {
41 JFFS2_WARNING("Can't allocate buffer for writing out summary information!\n");
46 dbg_summary("returned succesfully\n");
51 void jffs2_sum_exit(struct jffs2_sb_info *c)
53 dbg_summary("called\n");
55 jffs2_sum_disable_collecting(c->summary);
57 vfree(c->summary->sum_buf);
58 c->summary->sum_buf = NULL;
64 static int jffs2_sum_add_mem(struct jffs2_summary *s, union jffs2_sum_mem *item)
66 if (!s->sum_list_head)
67 s->sum_list_head = (union jffs2_sum_mem *) item;
69 s->sum_list_tail->u.next = (union jffs2_sum_mem *) item;
70 s->sum_list_tail = (union jffs2_sum_mem *) item;
72 switch (je16_to_cpu(item->u.nodetype)) {
73 case JFFS2_NODETYPE_INODE:
74 s->sum_size += JFFS2_SUMMARY_INODE_SIZE;
76 dbg_summary("inode (%u) added to summary\n",
77 je32_to_cpu(item->i.inode));
79 case JFFS2_NODETYPE_DIRENT:
80 s->sum_size += JFFS2_SUMMARY_DIRENT_SIZE(item->d.nsize);
82 dbg_summary("dirent (%u) added to summary\n",
83 je32_to_cpu(item->d.ino));
85 #ifdef CONFIG_JFFS2_FS_XATTR
86 case JFFS2_NODETYPE_XATTR:
87 s->sum_size += JFFS2_SUMMARY_XATTR_SIZE;
89 dbg_summary("xattr (xid=%u, version=%u) added to summary\n",
90 je32_to_cpu(item->x.xid), je32_to_cpu(item->x.version));
92 case JFFS2_NODETYPE_XREF:
93 s->sum_size += JFFS2_SUMMARY_XREF_SIZE;
95 dbg_summary("xref added to summary\n");
99 JFFS2_WARNING("UNKNOWN node type %u\n",
100 je16_to_cpu(item->u.nodetype));
107 /* The following 3 functions are called from scan.c to collect summary info for not closed jeb */
109 int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size)
111 dbg_summary("called with %u\n", size);
112 s->sum_padded += size;
116 int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri,
119 struct jffs2_sum_inode_mem *temp = kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
124 temp->nodetype = ri->nodetype;
125 temp->inode = ri->ino;
126 temp->version = ri->version;
127 temp->offset = cpu_to_je32(ofs); /* relative offset from the begining of the jeb */
128 temp->totlen = ri->totlen;
131 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
134 int jffs2_sum_add_dirent_mem(struct jffs2_summary *s, struct jffs2_raw_dirent *rd,
137 struct jffs2_sum_dirent_mem *temp =
138 kmalloc(sizeof(struct jffs2_sum_dirent_mem) + rd->nsize, GFP_KERNEL);
143 temp->nodetype = rd->nodetype;
144 temp->totlen = rd->totlen;
145 temp->offset = cpu_to_je32(ofs); /* relative from the begining of the jeb */
146 temp->pino = rd->pino;
147 temp->version = rd->version;
149 temp->nsize = rd->nsize;
150 temp->type = rd->type;
153 memcpy(temp->name, rd->name, rd->nsize);
155 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
158 #ifdef CONFIG_JFFS2_FS_XATTR
159 int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx, uint32_t ofs)
161 struct jffs2_sum_xattr_mem *temp;
163 temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
167 temp->nodetype = rx->nodetype;
169 temp->version = rx->version;
170 temp->offset = cpu_to_je32(ofs);
171 temp->totlen = rx->totlen;
174 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
177 int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, uint32_t ofs)
179 struct jffs2_sum_xref_mem *temp;
181 temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
185 temp->nodetype = rr->nodetype;
186 temp->offset = cpu_to_je32(ofs);
189 return jffs2_sum_add_mem(s, (union jffs2_sum_mem *)temp);
192 /* Cleanup every collected summary information */
194 static void jffs2_sum_clean_collected(struct jffs2_summary *s)
196 union jffs2_sum_mem *temp;
198 if (!s->sum_list_head) {
199 dbg_summary("already empty\n");
201 while (s->sum_list_head) {
202 temp = s->sum_list_head;
203 s->sum_list_head = s->sum_list_head->u.next;
206 s->sum_list_tail = NULL;
211 void jffs2_sum_reset_collected(struct jffs2_summary *s)
213 dbg_summary("called\n");
214 jffs2_sum_clean_collected(s);
218 void jffs2_sum_disable_collecting(struct jffs2_summary *s)
220 dbg_summary("called\n");
221 jffs2_sum_clean_collected(s);
222 s->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
225 int jffs2_sum_is_disabled(struct jffs2_summary *s)
227 return (s->sum_size == JFFS2_SUMMARY_NOSUM_SIZE);
230 /* Move the collected summary information into sb (called from scan.c) */
232 void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s)
234 dbg_summary("oldsize=0x%x oldnum=%u => newsize=0x%x newnum=%u\n",
235 c->summary->sum_size, c->summary->sum_num,
236 s->sum_size, s->sum_num);
238 c->summary->sum_size = s->sum_size;
239 c->summary->sum_num = s->sum_num;
240 c->summary->sum_padded = s->sum_padded;
241 c->summary->sum_list_head = s->sum_list_head;
242 c->summary->sum_list_tail = s->sum_list_tail;
244 s->sum_list_head = s->sum_list_tail = NULL;
247 /* Called from wbuf.c to collect writed node info */
249 int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
250 unsigned long count, uint32_t ofs)
252 union jffs2_node_union *node;
253 struct jffs2_eraseblock *jeb;
255 node = invecs[0].iov_base;
256 jeb = &c->blocks[ofs / c->sector_size];
259 switch (je16_to_cpu(node->u.nodetype)) {
260 case JFFS2_NODETYPE_INODE: {
261 struct jffs2_sum_inode_mem *temp =
262 kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
267 temp->nodetype = node->i.nodetype;
268 temp->inode = node->i.ino;
269 temp->version = node->i.version;
270 temp->offset = cpu_to_je32(ofs);
271 temp->totlen = node->i.totlen;
274 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
277 case JFFS2_NODETYPE_DIRENT: {
278 struct jffs2_sum_dirent_mem *temp =
279 kmalloc(sizeof(struct jffs2_sum_dirent_mem) + node->d.nsize, GFP_KERNEL);
284 temp->nodetype = node->d.nodetype;
285 temp->totlen = node->d.totlen;
286 temp->offset = cpu_to_je32(ofs);
287 temp->pino = node->d.pino;
288 temp->version = node->d.version;
289 temp->ino = node->d.ino;
290 temp->nsize = node->d.nsize;
291 temp->type = node->d.type;
296 memcpy(temp->name,node->d.name,node->d.nsize);
300 memcpy(temp->name,invecs[1].iov_base,node->d.nsize);
304 BUG(); /* impossible count value */
308 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
310 #ifdef CONFIG_JFFS2_FS_XATTR
311 case JFFS2_NODETYPE_XATTR: {
312 struct jffs2_sum_xattr_mem *temp;
313 if (je32_to_cpu(node->x.version) == 0xffffffff)
315 temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
319 temp->nodetype = node->x.nodetype;
320 temp->xid = node->x.xid;
321 temp->version = node->x.version;
322 temp->totlen = node->x.totlen;
323 temp->offset = cpu_to_je32(ofs);
326 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
328 case JFFS2_NODETYPE_XREF: {
329 struct jffs2_sum_xref_mem *temp;
331 if (je32_to_cpu(node->r.ino) == 0xffffffff
332 && je32_to_cpu(node->r.xid) == 0xffffffff)
334 temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
337 temp->nodetype = node->r.nodetype;
338 temp->offset = cpu_to_je32(ofs);
341 return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
344 case JFFS2_NODETYPE_PADDING:
345 dbg_summary("node PADDING\n");
346 c->summary->sum_padded += je32_to_cpu(node->u.totlen);
349 case JFFS2_NODETYPE_CLEANMARKER:
350 dbg_summary("node CLEANMARKER\n");
353 case JFFS2_NODETYPE_SUMMARY:
354 dbg_summary("node SUMMARY\n");
358 /* If you implement a new node type you should also implement
359 summary support for it or disable summary.
368 JFFS2_WARNING("MEMORY ALLOCATION ERROR!");
372 static struct jffs2_raw_node_ref *alloc_ref_at(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
375 struct jffs2_raw_node_ref *ref;
376 /* If there was a gap, mark it dirty */
377 if (offset > c->sector_size - jeb->free_size) {
378 int ret = jffs2_scan_dirty_space(c, jeb, offset - (c->sector_size - jeb->free_size));
382 ref = jffs2_alloc_raw_node_ref();
386 ref->flash_offset = jeb->offset + offset;
390 /* Process the stored summary information - helper function for jffs2_sum_scan_sumnode() */
392 static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
393 struct jffs2_raw_summary *summary, uint32_t *pseudo_random)
395 struct jffs2_raw_node_ref *raw;
396 struct jffs2_inode_cache *ic;
397 struct jffs2_full_dirent *fd;
404 for (i=0; i<je32_to_cpu(summary->sum_num); i++) {
405 dbg_summary("processing summary index %d\n", i);
407 switch (je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype)) {
408 case JFFS2_NODETYPE_INODE: {
409 struct jffs2_sum_inode_flash *spi;
412 ino = je32_to_cpu(spi->inode);
414 dbg_summary("Inode at 0x%08x\n",
415 jeb->offset + je32_to_cpu(spi->offset));
417 raw = alloc_ref_at(c, jeb, je32_to_cpu(spi->offset));
419 JFFS2_NOTICE("allocation of node reference failed\n");
423 ic = jffs2_scan_make_ino_cache(c, ino);
425 JFFS2_NOTICE("scan_make_ino_cache failed\n");
426 jffs2_free_raw_node_ref(raw);
430 raw->flash_offset |= REF_UNCHECKED;
432 raw->next_in_ino = ic->nodes;
435 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spi->totlen)));
437 *pseudo_random += je32_to_cpu(spi->version);
439 sp += JFFS2_SUMMARY_INODE_SIZE;
444 case JFFS2_NODETYPE_DIRENT: {
445 struct jffs2_sum_dirent_flash *spd;
448 dbg_summary("Dirent at 0x%08x\n",
449 jeb->offset + je32_to_cpu(spd->offset));
451 fd = jffs2_alloc_full_dirent(spd->nsize+1);
455 memcpy(&fd->name, spd->name, spd->nsize);
456 fd->name[spd->nsize] = 0;
458 raw = alloc_ref_at(c, jeb, je32_to_cpu(spd->offset));
460 jffs2_free_full_dirent(fd);
461 JFFS2_NOTICE("allocation of node reference failed\n");
465 ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(spd->pino));
467 jffs2_free_full_dirent(fd);
468 jffs2_free_raw_node_ref(raw);
472 raw->flash_offset |= REF_PRISTINE;
473 raw->next_in_ino = ic->nodes;
476 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spd->totlen)));
480 fd->version = je32_to_cpu(spd->version);
481 fd->ino = je32_to_cpu(spd->ino);
482 fd->nhash = full_name_hash(fd->name, spd->nsize);
483 fd->type = spd->type;
485 jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
487 *pseudo_random += je32_to_cpu(spd->version);
489 sp += JFFS2_SUMMARY_DIRENT_SIZE(spd->nsize);
493 #ifdef CONFIG_JFFS2_FS_XATTR
494 case JFFS2_NODETYPE_XATTR: {
495 struct jffs2_xattr_datum *xd;
496 struct jffs2_sum_xattr_flash *spx;
498 spx = (struct jffs2_sum_xattr_flash *)sp;
499 dbg_summary("xattr at %#08x (xid=%u, version=%u)\n",
500 jeb->offset + je32_to_cpu(spx->offset),
501 je32_to_cpu(spx->xid), je32_to_cpu(spx->version));
502 raw = alloc_ref_at(c, jeb, je32_to_cpu(spx->offset));
504 JFFS2_NOTICE("allocation of node reference failed\n");
508 xd = jffs2_setup_xattr_datum(c, je32_to_cpu(spx->xid),
509 je32_to_cpu(spx->version));
511 jffs2_free_raw_node_ref(raw);
512 if (PTR_ERR(xd) == -EEXIST) {
513 /* a newer version of xd exists */
514 if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(spx->totlen))))
516 sp += JFFS2_SUMMARY_XATTR_SIZE;
519 JFFS2_NOTICE("allocation of xattr_datum failed\n");
525 raw->flash_offset |= REF_UNCHECKED;
526 raw->next_in_ino = (void *)xd;
528 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spx->totlen)));
530 *pseudo_random += je32_to_cpu(spx->xid);
531 sp += JFFS2_SUMMARY_XATTR_SIZE;
535 case JFFS2_NODETYPE_XREF: {
536 struct jffs2_xattr_ref *ref;
537 struct jffs2_sum_xref_flash *spr;
539 spr = (struct jffs2_sum_xref_flash *)sp;
540 dbg_summary("xref at %#08x (xid=%u, ino=%u)\n",
541 jeb->offset + je32_to_cpu(spr->offset),
542 je32_to_cpu(spr->xid), je32_to_cpu(spr->ino));
543 raw = alloc_ref_at(c, jeb, je32_to_cpu(spr->offset));
545 JFFS2_NOTICE("allocation of node reference failed\n");
549 ref = jffs2_alloc_xattr_ref();
551 JFFS2_NOTICE("allocation of xattr_datum failed\n");
552 jffs2_free_raw_node_ref(raw);
556 ref->ino = 0xfffffffe;
557 ref->xid = 0xfffffffd;
559 ref->next = c->xref_temp;
562 raw->flash_offset |= REF_UNCHECKED;
563 raw->next_in_ino = (void *)ref;
565 jffs2_link_node_ref(c, jeb, raw, PAD(sizeof(struct jffs2_raw_xref)));
567 *pseudo_random += raw->flash_offset;
568 sp += JFFS2_SUMMARY_XREF_SIZE;
574 uint16_t nodetype = je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype);
575 JFFS2_WARNING("Unsupported node type %x found in summary! Exiting...\n", nodetype);
576 if ((nodetype & JFFS2_COMPAT_MASK) == JFFS2_FEATURE_INCOMPAT)
579 /* For compatible node types, just fall back to the full scan */
580 c->wasted_size -= jeb->wasted_size;
581 c->free_size += c->sector_size - jeb->free_size;
582 c->used_size -= jeb->used_size;
583 c->dirty_size -= jeb->dirty_size;
584 jeb->wasted_size = jeb->used_size = jeb->dirty_size = 0;
585 jeb->free_size = c->sector_size;
587 jffs2_free_all_node_refs(c, jeb);
588 return -ENOTRECOVERABLE;
596 /* Process the summary node - called from jffs2_scan_eraseblock() */
597 int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
598 struct jffs2_raw_summary *summary, uint32_t sumsize,
599 uint32_t *pseudo_random)
601 struct jffs2_unknown_node crcnode;
602 struct jffs2_raw_node_ref *cache_ref;
607 ofs = c->sector_size - sumsize;
609 dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
610 jeb->offset, jeb->offset + ofs, sumsize);
612 /* OK, now check for node validity and CRC */
613 crcnode.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
614 crcnode.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
615 crcnode.totlen = summary->totlen;
616 crc = crc32(0, &crcnode, sizeof(crcnode)-4);
618 if (je32_to_cpu(summary->hdr_crc) != crc) {
619 dbg_summary("Summary node header is corrupt (bad CRC or "
620 "no summary at all)\n");
624 if (je32_to_cpu(summary->totlen) != sumsize) {
625 dbg_summary("Summary node is corrupt (wrong erasesize?)\n");
629 crc = crc32(0, summary, sizeof(struct jffs2_raw_summary)-8);
631 if (je32_to_cpu(summary->node_crc) != crc) {
632 dbg_summary("Summary node is corrupt (bad CRC)\n");
636 crc = crc32(0, summary->sum, sumsize - sizeof(struct jffs2_raw_summary));
638 if (je32_to_cpu(summary->sum_crc) != crc) {
639 dbg_summary("Summary node data is corrupt (bad CRC)\n");
643 if ( je32_to_cpu(summary->cln_mkr) ) {
645 dbg_summary("Summary : CLEANMARKER node \n");
647 if (je32_to_cpu(summary->cln_mkr) != c->cleanmarker_size) {
648 dbg_summary("CLEANMARKER node has totlen 0x%x != normal 0x%x\n",
649 je32_to_cpu(summary->cln_mkr), c->cleanmarker_size);
650 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(summary->cln_mkr)))))
652 } else if (jeb->first_node) {
653 dbg_summary("CLEANMARKER node not first node in block "
654 "(0x%08x)\n", jeb->offset);
655 if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(summary->cln_mkr)))))
658 struct jffs2_raw_node_ref *marker_ref = jffs2_alloc_raw_node_ref();
661 JFFS2_NOTICE("Failed to allocate node ref for clean marker\n");
665 marker_ref->flash_offset = jeb->offset | REF_NORMAL;
666 marker_ref->next_in_ino = NULL;
668 jffs2_link_node_ref(c, jeb, marker_ref, je32_to_cpu(summary->cln_mkr));
672 ret = jffs2_sum_process_sum_data(c, jeb, summary, pseudo_random);
673 /* -ENOTRECOVERABLE isn't a fatal error -- it means we should do a full
674 scan of this eraseblock. So return zero */
675 if (ret == -ENOTRECOVERABLE)
678 return ret; /* real error */
680 /* for PARANOIA_CHECK */
681 cache_ref = alloc_ref_at(c, jeb, ofs);
684 JFFS2_NOTICE("Failed to allocate node ref for cache\n");
688 cache_ref->next_in_ino = NULL;
689 cache_ref->flash_offset |= REF_NORMAL;
691 jffs2_link_node_ref(c, jeb, cache_ref, sumsize);
693 if (unlikely(jeb->free_size)) {
694 JFFS2_WARNING("Free size 0x%x bytes in eraseblock @0x%08x with summary?\n",
695 jeb->free_size, jeb->offset);
696 jeb->wasted_size += jeb->free_size;
697 c->wasted_size += jeb->free_size;
698 c->free_size -= jeb->free_size;
702 return jffs2_scan_classify_jeb(c, jeb);
705 JFFS2_WARNING("Summary node crc error, skipping summary information.\n");
710 /* Write summary data to flash - helper function for jffs2_sum_write_sumnode() */
712 static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
713 uint32_t infosize, uint32_t datasize, int padsize)
715 struct jffs2_raw_summary isum;
716 union jffs2_sum_mem *temp;
717 struct jffs2_sum_marker *sm;
723 memset(c->summary->sum_buf, 0xff, datasize);
724 memset(&isum, 0, sizeof(isum));
726 isum.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
727 isum.nodetype = cpu_to_je16(JFFS2_NODETYPE_SUMMARY);
728 isum.totlen = cpu_to_je32(infosize);
729 isum.hdr_crc = cpu_to_je32(crc32(0, &isum, sizeof(struct jffs2_unknown_node) - 4));
730 isum.padded = cpu_to_je32(c->summary->sum_padded);
731 isum.cln_mkr = cpu_to_je32(c->cleanmarker_size);
732 isum.sum_num = cpu_to_je32(c->summary->sum_num);
733 wpage = c->summary->sum_buf;
735 while (c->summary->sum_num) {
736 temp = c->summary->sum_list_head;
738 switch (je16_to_cpu(temp->u.nodetype)) {
739 case JFFS2_NODETYPE_INODE: {
740 struct jffs2_sum_inode_flash *sino_ptr = wpage;
742 sino_ptr->nodetype = temp->i.nodetype;
743 sino_ptr->inode = temp->i.inode;
744 sino_ptr->version = temp->i.version;
745 sino_ptr->offset = temp->i.offset;
746 sino_ptr->totlen = temp->i.totlen;
748 wpage += JFFS2_SUMMARY_INODE_SIZE;
753 case JFFS2_NODETYPE_DIRENT: {
754 struct jffs2_sum_dirent_flash *sdrnt_ptr = wpage;
756 sdrnt_ptr->nodetype = temp->d.nodetype;
757 sdrnt_ptr->totlen = temp->d.totlen;
758 sdrnt_ptr->offset = temp->d.offset;
759 sdrnt_ptr->pino = temp->d.pino;
760 sdrnt_ptr->version = temp->d.version;
761 sdrnt_ptr->ino = temp->d.ino;
762 sdrnt_ptr->nsize = temp->d.nsize;
763 sdrnt_ptr->type = temp->d.type;
765 memcpy(sdrnt_ptr->name, temp->d.name,
768 wpage += JFFS2_SUMMARY_DIRENT_SIZE(temp->d.nsize);
772 #ifdef CONFIG_JFFS2_FS_XATTR
773 case JFFS2_NODETYPE_XATTR: {
774 struct jffs2_sum_xattr_flash *sxattr_ptr = wpage;
776 temp = c->summary->sum_list_head;
777 sxattr_ptr->nodetype = temp->x.nodetype;
778 sxattr_ptr->xid = temp->x.xid;
779 sxattr_ptr->version = temp->x.version;
780 sxattr_ptr->offset = temp->x.offset;
781 sxattr_ptr->totlen = temp->x.totlen;
783 wpage += JFFS2_SUMMARY_XATTR_SIZE;
786 case JFFS2_NODETYPE_XREF: {
787 struct jffs2_sum_xref_flash *sxref_ptr = wpage;
789 temp = c->summary->sum_list_head;
790 sxref_ptr->nodetype = temp->r.nodetype;
791 sxref_ptr->offset = temp->r.offset;
793 wpage += JFFS2_SUMMARY_XREF_SIZE;
798 if ((je16_to_cpu(temp->u.nodetype) & JFFS2_COMPAT_MASK)
799 == JFFS2_FEATURE_RWCOMPAT_COPY) {
800 dbg_summary("Writing unknown RWCOMPAT_COPY node type %x\n",
801 je16_to_cpu(temp->u.nodetype));
802 jffs2_sum_disable_collecting(c->summary);
804 BUG(); /* unknown node in summary information */
809 c->summary->sum_list_head = temp->u.next;
812 c->summary->sum_num--;
815 jffs2_sum_reset_collected(c->summary);
820 sm->offset = cpu_to_je32(c->sector_size - jeb->free_size);
821 sm->magic = cpu_to_je32(JFFS2_SUM_MAGIC);
823 isum.sum_crc = cpu_to_je32(crc32(0, c->summary->sum_buf, datasize));
824 isum.node_crc = cpu_to_je32(crc32(0, &isum, sizeof(isum) - 8));
826 vecs[0].iov_base = &isum;
827 vecs[0].iov_len = sizeof(isum);
828 vecs[1].iov_base = c->summary->sum_buf;
829 vecs[1].iov_len = datasize;
831 dbg_summary("JFFS2: writing out data to flash to pos : 0x%08x\n",
832 jeb->offset + c->sector_size - jeb->free_size);
834 spin_unlock(&c->erase_completion_lock);
835 ret = jffs2_flash_writev(c, vecs, 2, jeb->offset + c->sector_size -
836 jeb->free_size, &retlen, 0);
837 spin_lock(&c->erase_completion_lock);
840 if (ret || (retlen != infosize)) {
841 JFFS2_WARNING("Write of %u bytes at 0x%08x failed. returned %d, retlen %zd\n",
842 infosize, jeb->offset + c->sector_size - jeb->free_size, ret, retlen);
844 c->summary->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
845 jffs2_scan_dirty_space(c, jeb, infosize);
853 /* Write out summary information - called from jffs2_do_reserve_space */
855 int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
857 struct jffs2_raw_node_ref *summary_ref;
858 int datasize, infosize, padsize, ret;
859 struct jffs2_eraseblock *jeb;
861 dbg_summary("called\n");
865 if (!c->summary->sum_num || !c->summary->sum_list_head) {
866 JFFS2_WARNING("Empty summary info!!!\n");
870 datasize = c->summary->sum_size + sizeof(struct jffs2_sum_marker);
871 infosize = sizeof(struct jffs2_raw_summary) + datasize;
872 padsize = jeb->free_size - infosize;
876 /* Is there enough space for summary? */
878 /* don't try to write out summary for this jeb */
879 jffs2_sum_disable_collecting(c->summary);
881 JFFS2_WARNING("Not enough space for summary, padsize = %d\n", padsize);
885 ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
887 return 0; /* can't write out summary, block is marked as NOSUM_SIZE */
889 /* for ACCT_PARANOIA_CHECK */
890 spin_unlock(&c->erase_completion_lock);
891 summary_ref = jffs2_alloc_raw_node_ref();
892 spin_lock(&c->erase_completion_lock);
895 JFFS2_NOTICE("Failed to allocate node ref for summary\n");
899 summary_ref->next_in_ino = NULL;
900 summary_ref->flash_offset = (jeb->offset + c->sector_size - jeb->free_size) | REF_NORMAL;
902 jffs2_link_node_ref(c, jeb, summary_ref, infosize);