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 * 2006 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/slab.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/pagemap.h>
20 #include <linux/crc32.h>
21 #include <linux/compiler.h>
22 #include <linux/vmalloc.h>
26 int jffs2_sum_init(struct jffs2_sb_info
*c
)
28 c
->summary
= kzalloc(sizeof(struct jffs2_summary
), GFP_KERNEL
);
31 JFFS2_WARNING("Can't allocate memory for summary information!\n");
35 c
->summary
->sum_buf
= vmalloc(c
->sector_size
);
37 if (!c
->summary
->sum_buf
) {
38 JFFS2_WARNING("Can't allocate buffer for writing out summary information!\n");
43 dbg_summary("returned successfully\n");
48 void jffs2_sum_exit(struct jffs2_sb_info
*c
)
50 dbg_summary("called\n");
52 jffs2_sum_disable_collecting(c
->summary
);
54 vfree(c
->summary
->sum_buf
);
55 c
->summary
->sum_buf
= NULL
;
61 static int jffs2_sum_add_mem(struct jffs2_summary
*s
, union jffs2_sum_mem
*item
)
63 if (!s
->sum_list_head
)
64 s
->sum_list_head
= (union jffs2_sum_mem
*) item
;
66 s
->sum_list_tail
->u
.next
= (union jffs2_sum_mem
*) item
;
67 s
->sum_list_tail
= (union jffs2_sum_mem
*) item
;
69 switch (je16_to_cpu(item
->u
.nodetype
)) {
70 case JFFS2_NODETYPE_INODE
:
71 s
->sum_size
+= JFFS2_SUMMARY_INODE_SIZE
;
73 dbg_summary("inode (%u) added to summary\n",
74 je32_to_cpu(item
->i
.inode
));
76 case JFFS2_NODETYPE_DIRENT
:
77 s
->sum_size
+= JFFS2_SUMMARY_DIRENT_SIZE(item
->d
.nsize
);
79 dbg_summary("dirent (%u) added to summary\n",
80 je32_to_cpu(item
->d
.ino
));
82 #ifdef CONFIG_JFFS2_FS_XATTR
83 case JFFS2_NODETYPE_XATTR
:
84 s
->sum_size
+= JFFS2_SUMMARY_XATTR_SIZE
;
86 dbg_summary("xattr (xid=%u, version=%u) added to summary\n",
87 je32_to_cpu(item
->x
.xid
), je32_to_cpu(item
->x
.version
));
89 case JFFS2_NODETYPE_XREF
:
90 s
->sum_size
+= JFFS2_SUMMARY_XREF_SIZE
;
92 dbg_summary("xref added to summary\n");
96 JFFS2_WARNING("UNKNOWN node type %u\n",
97 je16_to_cpu(item
->u
.nodetype
));
104 /* The following 3 functions are called from scan.c to collect summary info for not closed jeb */
106 int jffs2_sum_add_padding_mem(struct jffs2_summary
*s
, uint32_t size
)
108 dbg_summary("called with %u\n", size
);
109 s
->sum_padded
+= size
;
113 int jffs2_sum_add_inode_mem(struct jffs2_summary
*s
, struct jffs2_raw_inode
*ri
,
116 struct jffs2_sum_inode_mem
*temp
= kmalloc(sizeof(struct jffs2_sum_inode_mem
), GFP_KERNEL
);
121 temp
->nodetype
= ri
->nodetype
;
122 temp
->inode
= ri
->ino
;
123 temp
->version
= ri
->version
;
124 temp
->offset
= cpu_to_je32(ofs
); /* relative offset from the begining of the jeb */
125 temp
->totlen
= ri
->totlen
;
128 return jffs2_sum_add_mem(s
, (union jffs2_sum_mem
*)temp
);
131 int jffs2_sum_add_dirent_mem(struct jffs2_summary
*s
, struct jffs2_raw_dirent
*rd
,
134 struct jffs2_sum_dirent_mem
*temp
=
135 kmalloc(sizeof(struct jffs2_sum_dirent_mem
) + rd
->nsize
, GFP_KERNEL
);
140 temp
->nodetype
= rd
->nodetype
;
141 temp
->totlen
= rd
->totlen
;
142 temp
->offset
= cpu_to_je32(ofs
); /* relative from the begining of the jeb */
143 temp
->pino
= rd
->pino
;
144 temp
->version
= rd
->version
;
146 temp
->nsize
= rd
->nsize
;
147 temp
->type
= rd
->type
;
150 memcpy(temp
->name
, rd
->name
, rd
->nsize
);
152 return jffs2_sum_add_mem(s
, (union jffs2_sum_mem
*)temp
);
155 #ifdef CONFIG_JFFS2_FS_XATTR
156 int jffs2_sum_add_xattr_mem(struct jffs2_summary
*s
, struct jffs2_raw_xattr
*rx
, uint32_t ofs
)
158 struct jffs2_sum_xattr_mem
*temp
;
160 temp
= kmalloc(sizeof(struct jffs2_sum_xattr_mem
), GFP_KERNEL
);
164 temp
->nodetype
= rx
->nodetype
;
166 temp
->version
= rx
->version
;
167 temp
->offset
= cpu_to_je32(ofs
);
168 temp
->totlen
= rx
->totlen
;
171 return jffs2_sum_add_mem(s
, (union jffs2_sum_mem
*)temp
);
174 int jffs2_sum_add_xref_mem(struct jffs2_summary
*s
, struct jffs2_raw_xref
*rr
, uint32_t ofs
)
176 struct jffs2_sum_xref_mem
*temp
;
178 temp
= kmalloc(sizeof(struct jffs2_sum_xref_mem
), GFP_KERNEL
);
182 temp
->nodetype
= rr
->nodetype
;
183 temp
->offset
= cpu_to_je32(ofs
);
186 return jffs2_sum_add_mem(s
, (union jffs2_sum_mem
*)temp
);
189 /* Cleanup every collected summary information */
191 static void jffs2_sum_clean_collected(struct jffs2_summary
*s
)
193 union jffs2_sum_mem
*temp
;
195 if (!s
->sum_list_head
) {
196 dbg_summary("already empty\n");
198 while (s
->sum_list_head
) {
199 temp
= s
->sum_list_head
;
200 s
->sum_list_head
= s
->sum_list_head
->u
.next
;
203 s
->sum_list_tail
= NULL
;
208 void jffs2_sum_reset_collected(struct jffs2_summary
*s
)
210 dbg_summary("called\n");
211 jffs2_sum_clean_collected(s
);
215 void jffs2_sum_disable_collecting(struct jffs2_summary
*s
)
217 dbg_summary("called\n");
218 jffs2_sum_clean_collected(s
);
219 s
->sum_size
= JFFS2_SUMMARY_NOSUM_SIZE
;
222 int jffs2_sum_is_disabled(struct jffs2_summary
*s
)
224 return (s
->sum_size
== JFFS2_SUMMARY_NOSUM_SIZE
);
227 /* Move the collected summary information into sb (called from scan.c) */
229 void jffs2_sum_move_collected(struct jffs2_sb_info
*c
, struct jffs2_summary
*s
)
231 dbg_summary("oldsize=0x%x oldnum=%u => newsize=0x%x newnum=%u\n",
232 c
->summary
->sum_size
, c
->summary
->sum_num
,
233 s
->sum_size
, s
->sum_num
);
235 c
->summary
->sum_size
= s
->sum_size
;
236 c
->summary
->sum_num
= s
->sum_num
;
237 c
->summary
->sum_padded
= s
->sum_padded
;
238 c
->summary
->sum_list_head
= s
->sum_list_head
;
239 c
->summary
->sum_list_tail
= s
->sum_list_tail
;
241 s
->sum_list_head
= s
->sum_list_tail
= NULL
;
244 /* Called from wbuf.c to collect writed node info */
246 int jffs2_sum_add_kvec(struct jffs2_sb_info
*c
, const struct kvec
*invecs
,
247 unsigned long count
, uint32_t ofs
)
249 union jffs2_node_union
*node
;
250 struct jffs2_eraseblock
*jeb
;
252 if (c
->summary
->sum_size
== JFFS2_SUMMARY_NOSUM_SIZE
) {
253 dbg_summary("Summary is disabled for this jeb! Skipping summary info!\n");
257 node
= invecs
[0].iov_base
;
258 jeb
= &c
->blocks
[ofs
/ c
->sector_size
];
261 switch (je16_to_cpu(node
->u
.nodetype
)) {
262 case JFFS2_NODETYPE_INODE
: {
263 struct jffs2_sum_inode_mem
*temp
=
264 kmalloc(sizeof(struct jffs2_sum_inode_mem
), GFP_KERNEL
);
269 temp
->nodetype
= node
->i
.nodetype
;
270 temp
->inode
= node
->i
.ino
;
271 temp
->version
= node
->i
.version
;
272 temp
->offset
= cpu_to_je32(ofs
);
273 temp
->totlen
= node
->i
.totlen
;
276 return jffs2_sum_add_mem(c
->summary
, (union jffs2_sum_mem
*)temp
);
279 case JFFS2_NODETYPE_DIRENT
: {
280 struct jffs2_sum_dirent_mem
*temp
=
281 kmalloc(sizeof(struct jffs2_sum_dirent_mem
) + node
->d
.nsize
, GFP_KERNEL
);
286 temp
->nodetype
= node
->d
.nodetype
;
287 temp
->totlen
= node
->d
.totlen
;
288 temp
->offset
= cpu_to_je32(ofs
);
289 temp
->pino
= node
->d
.pino
;
290 temp
->version
= node
->d
.version
;
291 temp
->ino
= node
->d
.ino
;
292 temp
->nsize
= node
->d
.nsize
;
293 temp
->type
= node
->d
.type
;
298 memcpy(temp
->name
,node
->d
.name
,node
->d
.nsize
);
302 memcpy(temp
->name
,invecs
[1].iov_base
,node
->d
.nsize
);
306 BUG(); /* impossible count value */
310 return jffs2_sum_add_mem(c
->summary
, (union jffs2_sum_mem
*)temp
);
312 #ifdef CONFIG_JFFS2_FS_XATTR
313 case JFFS2_NODETYPE_XATTR
: {
314 struct jffs2_sum_xattr_mem
*temp
;
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
;
330 temp
= kmalloc(sizeof(struct jffs2_sum_xref_mem
), GFP_KERNEL
);
333 temp
->nodetype
= node
->r
.nodetype
;
334 temp
->offset
= cpu_to_je32(ofs
);
337 return jffs2_sum_add_mem(c
->summary
, (union jffs2_sum_mem
*)temp
);
340 case JFFS2_NODETYPE_PADDING
:
341 dbg_summary("node PADDING\n");
342 c
->summary
->sum_padded
+= je32_to_cpu(node
->u
.totlen
);
345 case JFFS2_NODETYPE_CLEANMARKER
:
346 dbg_summary("node CLEANMARKER\n");
349 case JFFS2_NODETYPE_SUMMARY
:
350 dbg_summary("node SUMMARY\n");
354 /* If you implement a new node type you should also implement
355 summary support for it or disable summary.
364 JFFS2_WARNING("MEMORY ALLOCATION ERROR!");
368 static struct jffs2_raw_node_ref
*sum_link_node_ref(struct jffs2_sb_info
*c
,
369 struct jffs2_eraseblock
*jeb
,
370 uint32_t ofs
, uint32_t len
,
371 struct jffs2_inode_cache
*ic
)
373 /* If there was a gap, mark it dirty */
374 if ((ofs
& ~3) > c
->sector_size
- jeb
->free_size
) {
375 /* Ew. Summary doesn't actually tell us explicitly about dirty space */
376 jffs2_scan_dirty_space(c
, jeb
, (ofs
& ~3) - (c
->sector_size
- jeb
->free_size
));
379 return jffs2_link_node_ref(c
, jeb
, jeb
->offset
+ ofs
, len
, ic
);
382 /* Process the stored summary information - helper function for jffs2_sum_scan_sumnode() */
384 static int jffs2_sum_process_sum_data(struct jffs2_sb_info
*c
, struct jffs2_eraseblock
*jeb
,
385 struct jffs2_raw_summary
*summary
, uint32_t *pseudo_random
)
387 struct jffs2_inode_cache
*ic
;
388 struct jffs2_full_dirent
*fd
;
395 for (i
=0; i
<je32_to_cpu(summary
->sum_num
); i
++) {
396 dbg_summary("processing summary index %d\n", i
);
400 /* Make sure there's a spare ref for dirty space */
401 err
= jffs2_prealloc_raw_node_refs(c
, jeb
, 2);
405 switch (je16_to_cpu(((struct jffs2_sum_unknown_flash
*)sp
)->nodetype
)) {
406 case JFFS2_NODETYPE_INODE
: {
407 struct jffs2_sum_inode_flash
*spi
;
410 ino
= je32_to_cpu(spi
->inode
);
412 dbg_summary("Inode at 0x%08x-0x%08x\n",
413 jeb
->offset
+ je32_to_cpu(spi
->offset
),
414 jeb
->offset
+ je32_to_cpu(spi
->offset
) + je32_to_cpu(spi
->totlen
));
416 ic
= jffs2_scan_make_ino_cache(c
, ino
);
418 JFFS2_NOTICE("scan_make_ino_cache failed\n");
422 sum_link_node_ref(c
, jeb
, je32_to_cpu(spi
->offset
) | REF_UNCHECKED
,
423 PAD(je32_to_cpu(spi
->totlen
)), ic
);
425 *pseudo_random
+= je32_to_cpu(spi
->version
);
427 sp
+= JFFS2_SUMMARY_INODE_SIZE
;
432 case JFFS2_NODETYPE_DIRENT
: {
433 struct jffs2_sum_dirent_flash
*spd
;
436 dbg_summary("Dirent at 0x%08x-0x%08x\n",
437 jeb
->offset
+ je32_to_cpu(spd
->offset
),
438 jeb
->offset
+ je32_to_cpu(spd
->offset
) + je32_to_cpu(spd
->totlen
));
441 fd
= jffs2_alloc_full_dirent(spd
->nsize
+1);
445 memcpy(&fd
->name
, spd
->name
, spd
->nsize
);
446 fd
->name
[spd
->nsize
] = 0;
448 ic
= jffs2_scan_make_ino_cache(c
, je32_to_cpu(spd
->pino
));
450 jffs2_free_full_dirent(fd
);
454 fd
->raw
= sum_link_node_ref(c
, jeb
, je32_to_cpu(spd
->offset
) | REF_UNCHECKED
,
455 PAD(je32_to_cpu(spd
->totlen
)), ic
);
458 fd
->version
= je32_to_cpu(spd
->version
);
459 fd
->ino
= je32_to_cpu(spd
->ino
);
460 fd
->nhash
= full_name_hash(fd
->name
, spd
->nsize
);
461 fd
->type
= spd
->type
;
463 jffs2_add_fd_to_list(c
, fd
, &ic
->scan_dents
);
465 *pseudo_random
+= je32_to_cpu(spd
->version
);
467 sp
+= JFFS2_SUMMARY_DIRENT_SIZE(spd
->nsize
);
471 #ifdef CONFIG_JFFS2_FS_XATTR
472 case JFFS2_NODETYPE_XATTR
: {
473 struct jffs2_xattr_datum
*xd
;
474 struct jffs2_sum_xattr_flash
*spx
;
476 spx
= (struct jffs2_sum_xattr_flash
*)sp
;
477 dbg_summary("xattr at %#08x-%#08x (xid=%u, version=%u)\n",
478 jeb
->offset
+ je32_to_cpu(spx
->offset
),
479 jeb
->offset
+ je32_to_cpu(spx
->offset
) + je32_to_cpu(spx
->totlen
),
480 je32_to_cpu(spx
->xid
), je32_to_cpu(spx
->version
));
482 xd
= jffs2_setup_xattr_datum(c
, je32_to_cpu(spx
->xid
),
483 je32_to_cpu(spx
->version
));
486 if (xd
->version
> je32_to_cpu(spx
->version
)) {
487 /* node is not the newest one */
488 struct jffs2_raw_node_ref
*raw
489 = sum_link_node_ref(c
, jeb
, je32_to_cpu(spx
->offset
) | REF_UNCHECKED
,
490 PAD(je32_to_cpu(spx
->totlen
)), NULL
);
491 raw
->next_in_ino
= xd
->node
->next_in_ino
;
492 xd
->node
->next_in_ino
= raw
;
494 xd
->version
= je32_to_cpu(spx
->version
);
495 sum_link_node_ref(c
, jeb
, je32_to_cpu(spx
->offset
) | REF_UNCHECKED
,
496 PAD(je32_to_cpu(spx
->totlen
)), (void *)xd
);
498 *pseudo_random
+= je32_to_cpu(spx
->xid
);
499 sp
+= JFFS2_SUMMARY_XATTR_SIZE
;
503 case JFFS2_NODETYPE_XREF
: {
504 struct jffs2_xattr_ref
*ref
;
505 struct jffs2_sum_xref_flash
*spr
;
507 spr
= (struct jffs2_sum_xref_flash
*)sp
;
508 dbg_summary("xref at %#08x-%#08x\n",
509 jeb
->offset
+ je32_to_cpu(spr
->offset
),
510 jeb
->offset
+ je32_to_cpu(spr
->offset
) +
511 (uint32_t)PAD(sizeof(struct jffs2_raw_xref
)));
513 ref
= jffs2_alloc_xattr_ref();
515 JFFS2_NOTICE("allocation of xattr_datum failed\n");
518 ref
->next
= c
->xref_temp
;
521 sum_link_node_ref(c
, jeb
, je32_to_cpu(spr
->offset
) | REF_UNCHECKED
,
522 PAD(sizeof(struct jffs2_raw_xref
)), (void *)ref
);
524 *pseudo_random
+= ref
->node
->flash_offset
;
525 sp
+= JFFS2_SUMMARY_XREF_SIZE
;
531 uint16_t nodetype
= je16_to_cpu(((struct jffs2_sum_unknown_flash
*)sp
)->nodetype
);
532 JFFS2_WARNING("Unsupported node type %x found in summary! Exiting...\n", nodetype
);
533 if ((nodetype
& JFFS2_COMPAT_MASK
) == JFFS2_FEATURE_INCOMPAT
)
536 /* For compatible node types, just fall back to the full scan */
537 c
->wasted_size
-= jeb
->wasted_size
;
538 c
->free_size
+= c
->sector_size
- jeb
->free_size
;
539 c
->used_size
-= jeb
->used_size
;
540 c
->dirty_size
-= jeb
->dirty_size
;
541 jeb
->wasted_size
= jeb
->used_size
= jeb
->dirty_size
= 0;
542 jeb
->free_size
= c
->sector_size
;
544 jffs2_free_jeb_node_refs(c
, jeb
);
545 return -ENOTRECOVERABLE
;
552 /* Process the summary node - called from jffs2_scan_eraseblock() */
553 int jffs2_sum_scan_sumnode(struct jffs2_sb_info
*c
, struct jffs2_eraseblock
*jeb
,
554 struct jffs2_raw_summary
*summary
, uint32_t sumsize
,
555 uint32_t *pseudo_random
)
557 struct jffs2_unknown_node crcnode
;
561 ofs
= c
->sector_size
- sumsize
;
563 dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
564 jeb
->offset
, jeb
->offset
+ ofs
, sumsize
);
566 /* OK, now check for node validity and CRC */
567 crcnode
.magic
= cpu_to_je16(JFFS2_MAGIC_BITMASK
);
568 crcnode
.nodetype
= cpu_to_je16(JFFS2_NODETYPE_SUMMARY
);
569 crcnode
.totlen
= summary
->totlen
;
570 crc
= crc32(0, &crcnode
, sizeof(crcnode
)-4);
572 if (je32_to_cpu(summary
->hdr_crc
) != crc
) {
573 dbg_summary("Summary node header is corrupt (bad CRC or "
574 "no summary at all)\n");
578 if (je32_to_cpu(summary
->totlen
) != sumsize
) {
579 dbg_summary("Summary node is corrupt (wrong erasesize?)\n");
583 crc
= crc32(0, summary
, sizeof(struct jffs2_raw_summary
)-8);
585 if (je32_to_cpu(summary
->node_crc
) != crc
) {
586 dbg_summary("Summary node is corrupt (bad CRC)\n");
590 crc
= crc32(0, summary
->sum
, sumsize
- sizeof(struct jffs2_raw_summary
));
592 if (je32_to_cpu(summary
->sum_crc
) != crc
) {
593 dbg_summary("Summary node data is corrupt (bad CRC)\n");
597 if ( je32_to_cpu(summary
->cln_mkr
) ) {
599 dbg_summary("Summary : CLEANMARKER node \n");
601 ret
= jffs2_prealloc_raw_node_refs(c
, jeb
, 1);
605 if (je32_to_cpu(summary
->cln_mkr
) != c
->cleanmarker_size
) {
606 dbg_summary("CLEANMARKER node has totlen 0x%x != normal 0x%x\n",
607 je32_to_cpu(summary
->cln_mkr
), c
->cleanmarker_size
);
608 if ((ret
= jffs2_scan_dirty_space(c
, jeb
, PAD(je32_to_cpu(summary
->cln_mkr
)))))
610 } else if (jeb
->first_node
) {
611 dbg_summary("CLEANMARKER node not first node in block "
612 "(0x%08x)\n", jeb
->offset
);
613 if ((ret
= jffs2_scan_dirty_space(c
, jeb
, PAD(je32_to_cpu(summary
->cln_mkr
)))))
616 jffs2_link_node_ref(c
, jeb
, jeb
->offset
| REF_NORMAL
,
617 je32_to_cpu(summary
->cln_mkr
), NULL
);
621 ret
= jffs2_sum_process_sum_data(c
, jeb
, summary
, pseudo_random
);
622 /* -ENOTRECOVERABLE isn't a fatal error -- it means we should do a full
623 scan of this eraseblock. So return zero */
624 if (ret
== -ENOTRECOVERABLE
)
627 return ret
; /* real error */
629 /* for PARANOIA_CHECK */
630 ret
= jffs2_prealloc_raw_node_refs(c
, jeb
, 2);
634 sum_link_node_ref(c
, jeb
, ofs
| REF_NORMAL
, sumsize
, NULL
);
636 if (unlikely(jeb
->free_size
)) {
637 JFFS2_WARNING("Free size 0x%x bytes in eraseblock @0x%08x with summary?\n",
638 jeb
->free_size
, jeb
->offset
);
639 jeb
->wasted_size
+= jeb
->free_size
;
640 c
->wasted_size
+= jeb
->free_size
;
641 c
->free_size
-= jeb
->free_size
;
645 return jffs2_scan_classify_jeb(c
, jeb
);
648 JFFS2_WARNING("Summary node crc error, skipping summary information.\n");
653 /* Write summary data to flash - helper function for jffs2_sum_write_sumnode() */
655 static int jffs2_sum_write_data(struct jffs2_sb_info
*c
, struct jffs2_eraseblock
*jeb
,
656 uint32_t infosize
, uint32_t datasize
, int padsize
)
658 struct jffs2_raw_summary isum
;
659 union jffs2_sum_mem
*temp
;
660 struct jffs2_sum_marker
*sm
;
667 memset(c
->summary
->sum_buf
, 0xff, datasize
);
668 memset(&isum
, 0, sizeof(isum
));
670 isum
.magic
= cpu_to_je16(JFFS2_MAGIC_BITMASK
);
671 isum
.nodetype
= cpu_to_je16(JFFS2_NODETYPE_SUMMARY
);
672 isum
.totlen
= cpu_to_je32(infosize
);
673 isum
.hdr_crc
= cpu_to_je32(crc32(0, &isum
, sizeof(struct jffs2_unknown_node
) - 4));
674 isum
.padded
= cpu_to_je32(c
->summary
->sum_padded
);
675 isum
.cln_mkr
= cpu_to_je32(c
->cleanmarker_size
);
676 isum
.sum_num
= cpu_to_je32(c
->summary
->sum_num
);
677 wpage
= c
->summary
->sum_buf
;
679 while (c
->summary
->sum_num
) {
680 temp
= c
->summary
->sum_list_head
;
682 switch (je16_to_cpu(temp
->u
.nodetype
)) {
683 case JFFS2_NODETYPE_INODE
: {
684 struct jffs2_sum_inode_flash
*sino_ptr
= wpage
;
686 sino_ptr
->nodetype
= temp
->i
.nodetype
;
687 sino_ptr
->inode
= temp
->i
.inode
;
688 sino_ptr
->version
= temp
->i
.version
;
689 sino_ptr
->offset
= temp
->i
.offset
;
690 sino_ptr
->totlen
= temp
->i
.totlen
;
692 wpage
+= JFFS2_SUMMARY_INODE_SIZE
;
697 case JFFS2_NODETYPE_DIRENT
: {
698 struct jffs2_sum_dirent_flash
*sdrnt_ptr
= wpage
;
700 sdrnt_ptr
->nodetype
= temp
->d
.nodetype
;
701 sdrnt_ptr
->totlen
= temp
->d
.totlen
;
702 sdrnt_ptr
->offset
= temp
->d
.offset
;
703 sdrnt_ptr
->pino
= temp
->d
.pino
;
704 sdrnt_ptr
->version
= temp
->d
.version
;
705 sdrnt_ptr
->ino
= temp
->d
.ino
;
706 sdrnt_ptr
->nsize
= temp
->d
.nsize
;
707 sdrnt_ptr
->type
= temp
->d
.type
;
709 memcpy(sdrnt_ptr
->name
, temp
->d
.name
,
712 wpage
+= JFFS2_SUMMARY_DIRENT_SIZE(temp
->d
.nsize
);
716 #ifdef CONFIG_JFFS2_FS_XATTR
717 case JFFS2_NODETYPE_XATTR
: {
718 struct jffs2_sum_xattr_flash
*sxattr_ptr
= wpage
;
720 temp
= c
->summary
->sum_list_head
;
721 sxattr_ptr
->nodetype
= temp
->x
.nodetype
;
722 sxattr_ptr
->xid
= temp
->x
.xid
;
723 sxattr_ptr
->version
= temp
->x
.version
;
724 sxattr_ptr
->offset
= temp
->x
.offset
;
725 sxattr_ptr
->totlen
= temp
->x
.totlen
;
727 wpage
+= JFFS2_SUMMARY_XATTR_SIZE
;
730 case JFFS2_NODETYPE_XREF
: {
731 struct jffs2_sum_xref_flash
*sxref_ptr
= wpage
;
733 temp
= c
->summary
->sum_list_head
;
734 sxref_ptr
->nodetype
= temp
->r
.nodetype
;
735 sxref_ptr
->offset
= temp
->r
.offset
;
737 wpage
+= JFFS2_SUMMARY_XREF_SIZE
;
742 if ((je16_to_cpu(temp
->u
.nodetype
) & JFFS2_COMPAT_MASK
)
743 == JFFS2_FEATURE_RWCOMPAT_COPY
) {
744 dbg_summary("Writing unknown RWCOMPAT_COPY node type %x\n",
745 je16_to_cpu(temp
->u
.nodetype
));
746 jffs2_sum_disable_collecting(c
->summary
);
748 BUG(); /* unknown node in summary information */
753 c
->summary
->sum_list_head
= temp
->u
.next
;
756 c
->summary
->sum_num
--;
759 jffs2_sum_reset_collected(c
->summary
);
764 sm
->offset
= cpu_to_je32(c
->sector_size
- jeb
->free_size
);
765 sm
->magic
= cpu_to_je32(JFFS2_SUM_MAGIC
);
767 isum
.sum_crc
= cpu_to_je32(crc32(0, c
->summary
->sum_buf
, datasize
));
768 isum
.node_crc
= cpu_to_je32(crc32(0, &isum
, sizeof(isum
) - 8));
770 vecs
[0].iov_base
= &isum
;
771 vecs
[0].iov_len
= sizeof(isum
);
772 vecs
[1].iov_base
= c
->summary
->sum_buf
;
773 vecs
[1].iov_len
= datasize
;
775 sum_ofs
= jeb
->offset
+ c
->sector_size
- jeb
->free_size
;
777 dbg_summary("JFFS2: writing out data to flash to pos : 0x%08x\n",
780 ret
= jffs2_flash_writev(c
, vecs
, 2, sum_ofs
, &retlen
, 0);
782 if (ret
|| (retlen
!= infosize
)) {
784 JFFS2_WARNING("Write of %u bytes at 0x%08x failed. returned %d, retlen %zd\n",
785 infosize
, sum_ofs
, ret
, retlen
);
788 /* Waste remaining space */
789 spin_lock(&c
->erase_completion_lock
);
790 jffs2_link_node_ref(c
, jeb
, sum_ofs
| REF_OBSOLETE
, infosize
, NULL
);
791 spin_unlock(&c
->erase_completion_lock
);
794 c
->summary
->sum_size
= JFFS2_SUMMARY_NOSUM_SIZE
;
799 spin_lock(&c
->erase_completion_lock
);
800 jffs2_link_node_ref(c
, jeb
, sum_ofs
| REF_NORMAL
, infosize
, NULL
);
801 spin_unlock(&c
->erase_completion_lock
);
806 /* Write out summary information - called from jffs2_do_reserve_space */
808 int jffs2_sum_write_sumnode(struct jffs2_sb_info
*c
)
810 int datasize
, infosize
, padsize
;
811 struct jffs2_eraseblock
*jeb
;
814 dbg_summary("called\n");
816 spin_unlock(&c
->erase_completion_lock
);
819 jffs2_prealloc_raw_node_refs(c
, jeb
, 1);
821 if (!c
->summary
->sum_num
|| !c
->summary
->sum_list_head
) {
822 JFFS2_WARNING("Empty summary info!!!\n");
826 datasize
= c
->summary
->sum_size
+ sizeof(struct jffs2_sum_marker
);
827 infosize
= sizeof(struct jffs2_raw_summary
) + datasize
;
828 padsize
= jeb
->free_size
- infosize
;
832 /* Is there enough space for summary? */
834 /* don't try to write out summary for this jeb */
835 jffs2_sum_disable_collecting(c
->summary
);
837 JFFS2_WARNING("Not enough space for summary, padsize = %d\n", padsize
);
838 spin_lock(&c
->erase_completion_lock
);
842 ret
= jffs2_sum_write_data(c
, jeb
, infosize
, datasize
, padsize
);
843 spin_lock(&c
->erase_completion_lock
);