aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@cruncher.tec.linutronix.de>2006-05-23 06:37:31 -0400
committerThomas Gleixner <tglx@cruncher.tec.linutronix.de>2006-05-23 06:37:31 -0400
commit4cbb9b80e171107c6c34116283fe38e5a396c68b (patch)
tree9463f2e4774f14752cf4bb52431e14e569256f72 /fs/jffs2
parent6dfc6d250d0b7ebaa6423c44dcd09fcfe68deabd (diff)
parent9fe4854cd1f60273f9a3ece053f4789605f58a5e (diff)
Merge branch 'master' of /home/tglx/work/kernel/git/mtd-2.6/
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'fs/jffs2')
-rw-r--r--fs/jffs2/dir.c40
-rw-r--r--fs/jffs2/erase.c4
-rw-r--r--fs/jffs2/file.c8
-rw-r--r--fs/jffs2/fs.c20
-rw-r--r--fs/jffs2/gc.c51
-rw-r--r--fs/jffs2/nodelist.c13
-rw-r--r--fs/jffs2/nodelist.h75
-rw-r--r--fs/jffs2/nodemgmt.c35
-rw-r--r--fs/jffs2/os-linux.h14
-rw-r--r--fs/jffs2/scan.c24
-rw-r--r--fs/jffs2/summary.c30
-rw-r--r--fs/jffs2/wbuf.c52
-rw-r--r--fs/jffs2/write.c85
-rw-r--r--fs/jffs2/xattr.c60
-rw-r--r--fs/jffs2/xattr.h14
15 files changed, 234 insertions, 291 deletions
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index ff1b7950dd44..edd8371fc6a5 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -308,7 +308,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
308 struct jffs2_full_dnode *fn; 308 struct jffs2_full_dnode *fn;
309 struct jffs2_full_dirent *fd; 309 struct jffs2_full_dirent *fd;
310 int namelen; 310 int namelen;
311 uint32_t alloclen, phys_ofs; 311 uint32_t alloclen;
312 int ret, targetlen = strlen(target); 312 int ret, targetlen = strlen(target);
313 313
314 /* FIXME: If you care. We'd need to use frags for the target 314 /* FIXME: If you care. We'd need to use frags for the target
@@ -327,8 +327,8 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
327 * Just the node will do for now, though 327 * Just the node will do for now, though
328 */ 328 */
329 namelen = dentry->d_name.len; 329 namelen = dentry->d_name.len;
330 ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &phys_ofs, &alloclen, 330 ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &alloclen,
331 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 331 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
332 332
333 if (ret) { 333 if (ret) {
334 jffs2_free_raw_inode(ri); 334 jffs2_free_raw_inode(ri);
@@ -356,7 +356,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
356 ri->data_crc = cpu_to_je32(crc32(0, target, targetlen)); 356 ri->data_crc = cpu_to_je32(crc32(0, target, targetlen));
357 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 357 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
358 358
359 fn = jffs2_write_dnode(c, f, ri, target, targetlen, phys_ofs, ALLOC_NORMAL); 359 fn = jffs2_write_dnode(c, f, ri, target, targetlen, ALLOC_NORMAL);
360 360
361 jffs2_free_raw_inode(ri); 361 jffs2_free_raw_inode(ri);
362 362
@@ -400,8 +400,8 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
400 return ret; 400 return ret;
401 } 401 }
402 402
403 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 403 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
404 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 404 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
405 if (ret) { 405 if (ret) {
406 /* Eep. */ 406 /* Eep. */
407 jffs2_clear_inode(inode); 407 jffs2_clear_inode(inode);
@@ -433,7 +433,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
433 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 433 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
434 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 434 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
435 435
436 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); 436 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
437 437
438 if (IS_ERR(fd)) { 438 if (IS_ERR(fd)) {
439 /* dirent failed to write. Delete the inode normally 439 /* dirent failed to write. Delete the inode normally
@@ -471,7 +471,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
471 struct jffs2_full_dnode *fn; 471 struct jffs2_full_dnode *fn;
472 struct jffs2_full_dirent *fd; 472 struct jffs2_full_dirent *fd;
473 int namelen; 473 int namelen;
474 uint32_t alloclen, phys_ofs; 474 uint32_t alloclen;
475 int ret; 475 int ret;
476 476
477 mode |= S_IFDIR; 477 mode |= S_IFDIR;
@@ -486,8 +486,8 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
486 * Just the node will do for now, though 486 * Just the node will do for now, though
487 */ 487 */
488 namelen = dentry->d_name.len; 488 namelen = dentry->d_name.len;
489 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL, 489 ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
490 JFFS2_SUMMARY_INODE_SIZE); 490 JFFS2_SUMMARY_INODE_SIZE);
491 491
492 if (ret) { 492 if (ret) {
493 jffs2_free_raw_inode(ri); 493 jffs2_free_raw_inode(ri);
@@ -512,7 +512,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
512 ri->data_crc = cpu_to_je32(0); 512 ri->data_crc = cpu_to_je32(0);
513 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 513 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
514 514
515 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL); 515 fn = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL);
516 516
517 jffs2_free_raw_inode(ri); 517 jffs2_free_raw_inode(ri);
518 518
@@ -542,8 +542,8 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
542 return ret; 542 return ret;
543 } 543 }
544 544
545 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 545 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
546 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 546 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
547 if (ret) { 547 if (ret) {
548 /* Eep. */ 548 /* Eep. */
549 jffs2_clear_inode(inode); 549 jffs2_clear_inode(inode);
@@ -575,7 +575,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
575 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 575 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
576 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 576 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
577 577
578 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); 578 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
579 579
580 if (IS_ERR(fd)) { 580 if (IS_ERR(fd)) {
581 /* dirent failed to write. Delete the inode normally 581 /* dirent failed to write. Delete the inode normally
@@ -631,7 +631,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
631 int namelen; 631 int namelen;
632 union jffs2_device_node dev; 632 union jffs2_device_node dev;
633 int devlen = 0; 633 int devlen = 0;
634 uint32_t alloclen, phys_ofs; 634 uint32_t alloclen;
635 int ret; 635 int ret;
636 636
637 if (!new_valid_dev(rdev)) 637 if (!new_valid_dev(rdev))
@@ -650,7 +650,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
650 * Just the node will do for now, though 650 * Just the node will do for now, though
651 */ 651 */
652 namelen = dentry->d_name.len; 652 namelen = dentry->d_name.len;
653 ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &phys_ofs, &alloclen, 653 ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &alloclen,
654 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 654 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
655 655
656 if (ret) { 656 if (ret) {
@@ -678,7 +678,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
678 ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen)); 678 ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen));
679 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 679 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
680 680
681 fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, phys_ofs, ALLOC_NORMAL); 681 fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, ALLOC_NORMAL);
682 682
683 jffs2_free_raw_inode(ri); 683 jffs2_free_raw_inode(ri);
684 684
@@ -708,8 +708,8 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
708 return ret; 708 return ret;
709 } 709 }
710 710
711 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 711 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
712 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 712 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
713 if (ret) { 713 if (ret) {
714 /* Eep. */ 714 /* Eep. */
715 jffs2_clear_inode(inode); 715 jffs2_clear_inode(inode);
@@ -744,7 +744,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
744 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 744 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
745 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen)); 745 rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
746 746
747 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, phys_ofs, ALLOC_NORMAL); 747 fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
748 748
749 if (IS_ERR(fd)) { 749 if (IS_ERR(fd)) {
750 /* dirent failed to write. Delete the inode normally 750 /* dirent failed to write. Delete the inode normally
diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
index f677d6950fd4..4616fed75730 100644
--- a/fs/jffs2/erase.c
+++ b/fs/jffs2/erase.c
@@ -230,6 +230,7 @@ static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
230 at the end of the linked list. Stash it and continue 230 at the end of the linked list. Stash it and continue
231 from the beginning of the list */ 231 from the beginning of the list */
232 ic = (struct jffs2_inode_cache *)(*prev); 232 ic = (struct jffs2_inode_cache *)(*prev);
233 BUG_ON(ic->class != RAWNODE_CLASS_INODE_CACHE);
233 prev = &ic->nodes; 234 prev = &ic->nodes;
234 continue; 235 continue;
235 } 236 }
@@ -410,10 +411,9 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
410 /* Everything else got zeroed before the erase */ 411 /* Everything else got zeroed before the erase */
411 jeb->free_size = c->sector_size; 412 jeb->free_size = c->sector_size;
412 413
413 marker_ref->next_in_ino = NULL;
414 marker_ref->flash_offset = jeb->offset | REF_NORMAL; 414 marker_ref->flash_offset = jeb->offset | REF_NORMAL;
415 415
416 jffs2_link_node_ref(c, jeb, marker_ref, c->cleanmarker_size); 416 jffs2_link_node_ref(c, jeb, marker_ref, c->cleanmarker_size, NULL);
417 } 417 }
418 418
419 spin_lock(&c->erase_completion_lock); 419 spin_lock(&c->erase_completion_lock);
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
index e18c9437d58f..bb8844f40e48 100644
--- a/fs/jffs2/file.c
+++ b/fs/jffs2/file.c
@@ -134,13 +134,13 @@ static int jffs2_prepare_write (struct file *filp, struct page *pg,
134 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); 134 struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
135 struct jffs2_raw_inode ri; 135 struct jffs2_raw_inode ri;
136 struct jffs2_full_dnode *fn; 136 struct jffs2_full_dnode *fn;
137 uint32_t phys_ofs, alloc_len; 137 uint32_t alloc_len;
138 138
139 D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n", 139 D1(printk(KERN_DEBUG "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
140 (unsigned int)inode->i_size, pageofs)); 140 (unsigned int)inode->i_size, pageofs));
141 141
142 ret = jffs2_reserve_space(c, sizeof(ri), &phys_ofs, &alloc_len, 142 ret = jffs2_reserve_space(c, sizeof(ri), &alloc_len,
143 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 143 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
144 if (ret) 144 if (ret)
145 return ret; 145 return ret;
146 146
@@ -166,7 +166,7 @@ static int jffs2_prepare_write (struct file *filp, struct page *pg,
166 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); 166 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
167 ri.data_crc = cpu_to_je32(0); 167 ri.data_crc = cpu_to_je32(0);
168 168
169 fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, ALLOC_NORMAL); 169 fn = jffs2_write_dnode(c, f, &ri, NULL, 0, ALLOC_NORMAL);
170 170
171 if (IS_ERR(fn)) { 171 if (IS_ERR(fn)) {
172 ret = PTR_ERR(fn); 172 ret = PTR_ERR(fn);
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index a0f84673ce54..7b6c24b14f85 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -37,7 +37,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
37 unsigned char *mdata = NULL; 37 unsigned char *mdata = NULL;
38 int mdatalen = 0; 38 int mdatalen = 0;
39 unsigned int ivalid; 39 unsigned int ivalid;
40 uint32_t phys_ofs, alloclen; 40 uint32_t alloclen;
41 int ret; 41 int ret;
42 D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino)); 42 D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino));
43 ret = inode_change_ok(inode, iattr); 43 ret = inode_change_ok(inode, iattr);
@@ -79,8 +79,8 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
79 return -ENOMEM; 79 return -ENOMEM;
80 } 80 }
81 81
82 ret = jffs2_reserve_space(c, sizeof(*ri) + mdatalen, &phys_ofs, &alloclen, 82 ret = jffs2_reserve_space(c, sizeof(*ri) + mdatalen, &alloclen,
83 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 83 ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
84 if (ret) { 84 if (ret) {
85 jffs2_free_raw_inode(ri); 85 jffs2_free_raw_inode(ri);
86 if (S_ISLNK(inode->i_mode & S_IFMT)) 86 if (S_ISLNK(inode->i_mode & S_IFMT))
@@ -131,7 +131,7 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
131 else 131 else
132 ri->data_crc = cpu_to_je32(0); 132 ri->data_crc = cpu_to_je32(0);
133 133
134 new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, phys_ofs, ALLOC_NORMAL); 134 new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, ALLOC_NORMAL);
135 if (S_ISLNK(inode->i_mode)) 135 if (S_ISLNK(inode->i_mode))
136 kfree(mdata); 136 kfree(mdata);
137 137
@@ -664,13 +664,6 @@ static int jffs2_flash_setup(struct jffs2_sb_info *c) {
664 return ret; 664 return ret;
665 } 665 }
666 666
667 /* add setups for other bizarre flashes here... */
668 if (jffs2_nor_ecc(c)) {
669 ret = jffs2_nor_ecc_flash_setup(c);
670 if (ret)
671 return ret;
672 }
673
674 /* and Dataflash */ 667 /* and Dataflash */
675 if (jffs2_dataflash(c)) { 668 if (jffs2_dataflash(c)) {
676 ret = jffs2_dataflash_setup(c); 669 ret = jffs2_dataflash_setup(c);
@@ -694,11 +687,6 @@ void jffs2_flash_cleanup(struct jffs2_sb_info *c) {
694 jffs2_nand_flash_cleanup(c); 687 jffs2_nand_flash_cleanup(c);
695 } 688 }
696 689
697 /* add cleanups for other bizarre flashes here... */
698 if (jffs2_nor_ecc(c)) {
699 jffs2_nor_ecc_flash_cleanup(c);
700 }
701
702 /* and DataFlash */ 690 /* and DataFlash */
703 if (jffs2_dataflash(c)) { 691 if (jffs2_dataflash(c)) {
704 jffs2_dataflash_cleanup(c); 692 jffs2_dataflash_cleanup(c);
diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c
index 4773ba24304f..f9e982a65ac2 100644
--- a/fs/jffs2/gc.c
+++ b/fs/jffs2/gc.c
@@ -545,7 +545,7 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
545 if (ic && alloclen > sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN) 545 if (ic && alloclen > sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN)
546 alloclen = sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN; 546 alloclen = sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN;
547 547
548 ret = jffs2_reserve_space_gc(c, alloclen, &phys_ofs, &alloclen, rawlen); 548 ret = jffs2_reserve_space_gc(c, alloclen, &alloclen, rawlen);
549 /* 'rawlen' is not the exact summary size; it is only an upper estimation */ 549 /* 'rawlen' is not the exact summary size; it is only an upper estimation */
550 550
551 if (ret) 551 if (ret)
@@ -626,19 +626,16 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
626 626
627 /* OK, all the CRCs are good; this node can just be copied as-is. */ 627 /* OK, all the CRCs are good; this node can just be copied as-is. */
628 retry: 628 retry:
629 nraw->flash_offset = phys_ofs; 629 nraw->flash_offset = phys_ofs = write_ofs(c);
630 630
631 ret = jffs2_flash_write(c, phys_ofs, rawlen, &retlen, (char *)node); 631 ret = jffs2_flash_write(c, phys_ofs, rawlen, &retlen, (char *)node);
632 632
633 if (ret || (retlen != rawlen)) { 633 if (ret || (retlen != rawlen)) {
634 printk(KERN_NOTICE "Write of %d bytes at 0x%08x failed. returned %d, retlen %zd\n", 634 printk(KERN_NOTICE "Write of %d bytes at 0x%08x failed. returned %d, retlen %zd\n",
635 rawlen, phys_ofs, ret, retlen); 635 rawlen, nraw->flash_offset, ret, retlen);
636 if (retlen) { 636 if (retlen) {
637 /* Doesn't belong to any inode */
638 nraw->next_in_ino = NULL;
639
640 nraw->flash_offset |= REF_OBSOLETE; 637 nraw->flash_offset |= REF_OBSOLETE;
641 jffs2_add_physical_node_ref(c, nraw, rawlen); 638 jffs2_add_physical_node_ref(c, nraw, rawlen, NULL);
642 jffs2_mark_node_obsolete(c, nraw); 639 jffs2_mark_node_obsolete(c, nraw);
643 } else { 640 } else {
644 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", nraw->flash_offset); 641 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", nraw->flash_offset);
@@ -656,7 +653,7 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
656 jffs2_dbg_acct_sanity_check(c,jeb); 653 jffs2_dbg_acct_sanity_check(c,jeb);
657 jffs2_dbg_acct_paranoia_check(c, jeb); 654 jffs2_dbg_acct_paranoia_check(c, jeb);
658 655
659 ret = jffs2_reserve_space_gc(c, rawlen, &phys_ofs, &dummy, rawlen); 656 ret = jffs2_reserve_space_gc(c, rawlen, &dummy, rawlen);
660 /* this is not the exact summary size of it, 657 /* this is not the exact summary size of it,
661 it is only an upper estimation */ 658 it is only an upper estimation */
662 659
@@ -678,18 +675,8 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
678 goto out_node; 675 goto out_node;
679 } 676 }
680 nraw->flash_offset |= REF_PRISTINE; 677 nraw->flash_offset |= REF_PRISTINE;
681 jffs2_add_physical_node_ref(c, nraw, rawlen); 678 jffs2_add_physical_node_ref(c, nraw, rawlen, ic);
682 679
683 if (ic) {
684 /* Link into per-inode list. This is safe because of the ic
685 state being INO_STATE_GC. Note that if we're doing this
686 for an inode which is in-core, the 'nraw' pointer is then
687 going to be fetched from ic->nodes by our caller. */
688 spin_lock(&c->erase_completion_lock);
689 nraw->next_in_ino = ic->nodes;
690 ic->nodes = nraw;
691 spin_unlock(&c->erase_completion_lock);
692 }
693 jffs2_mark_node_obsolete(c, raw); 680 jffs2_mark_node_obsolete(c, raw);
694 D1(printk(KERN_DEBUG "WHEEE! GC REF_PRISTINE node at 0x%08x succeeded\n", ref_offset(raw))); 681 D1(printk(KERN_DEBUG "WHEEE! GC REF_PRISTINE node at 0x%08x succeeded\n", ref_offset(raw)));
695 682
@@ -709,7 +696,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
709 struct jffs2_node_frag *last_frag; 696 struct jffs2_node_frag *last_frag;
710 union jffs2_device_node dev; 697 union jffs2_device_node dev;
711 char *mdata = NULL, mdatalen = 0; 698 char *mdata = NULL, mdatalen = 0;
712 uint32_t alloclen, phys_ofs, ilen; 699 uint32_t alloclen, ilen;
713 int ret; 700 int ret;
714 701
715 if (S_ISBLK(JFFS2_F_I_MODE(f)) || 702 if (S_ISBLK(JFFS2_F_I_MODE(f)) ||
@@ -735,7 +722,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
735 722
736 } 723 }
737 724
738 ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &phys_ofs, &alloclen, 725 ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &alloclen,
739 JFFS2_SUMMARY_INODE_SIZE); 726 JFFS2_SUMMARY_INODE_SIZE);
740 if (ret) { 727 if (ret) {
741 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_metadata failed: %d\n", 728 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_metadata failed: %d\n",
@@ -773,7 +760,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
773 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); 760 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
774 ri.data_crc = cpu_to_je32(crc32(0, mdata, mdatalen)); 761 ri.data_crc = cpu_to_je32(crc32(0, mdata, mdatalen));
775 762
776 new_fn = jffs2_write_dnode(c, f, &ri, mdata, mdatalen, phys_ofs, ALLOC_GC); 763 new_fn = jffs2_write_dnode(c, f, &ri, mdata, mdatalen, ALLOC_GC);
777 764
778 if (IS_ERR(new_fn)) { 765 if (IS_ERR(new_fn)) {
779 printk(KERN_WARNING "Error writing new dnode: %ld\n", PTR_ERR(new_fn)); 766 printk(KERN_WARNING "Error writing new dnode: %ld\n", PTR_ERR(new_fn));
@@ -794,7 +781,7 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
794{ 781{
795 struct jffs2_full_dirent *new_fd; 782 struct jffs2_full_dirent *new_fd;
796 struct jffs2_raw_dirent rd; 783 struct jffs2_raw_dirent rd;
797 uint32_t alloclen, phys_ofs; 784 uint32_t alloclen;
798 int ret; 785 int ret;
799 786
800 rd.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 787 rd.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -816,14 +803,14 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
816 rd.node_crc = cpu_to_je32(crc32(0, &rd, sizeof(rd)-8)); 803 rd.node_crc = cpu_to_je32(crc32(0, &rd, sizeof(rd)-8));
817 rd.name_crc = cpu_to_je32(crc32(0, fd->name, rd.nsize)); 804 rd.name_crc = cpu_to_je32(crc32(0, fd->name, rd.nsize));
818 805
819 ret = jffs2_reserve_space_gc(c, sizeof(rd)+rd.nsize, &phys_ofs, &alloclen, 806 ret = jffs2_reserve_space_gc(c, sizeof(rd)+rd.nsize, &alloclen,
820 JFFS2_SUMMARY_DIRENT_SIZE(rd.nsize)); 807 JFFS2_SUMMARY_DIRENT_SIZE(rd.nsize));
821 if (ret) { 808 if (ret) {
822 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_dirent failed: %d\n", 809 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_dirent failed: %d\n",
823 sizeof(rd)+rd.nsize, ret); 810 sizeof(rd)+rd.nsize, ret);
824 return ret; 811 return ret;
825 } 812 }
826 new_fd = jffs2_write_dirent(c, f, &rd, fd->name, rd.nsize, phys_ofs, ALLOC_GC); 813 new_fd = jffs2_write_dirent(c, f, &rd, fd->name, rd.nsize, ALLOC_GC);
827 814
828 if (IS_ERR(new_fd)) { 815 if (IS_ERR(new_fd)) {
829 printk(KERN_WARNING "jffs2_write_dirent in garbage_collect_dirent failed: %ld\n", PTR_ERR(new_fd)); 816 printk(KERN_WARNING "jffs2_write_dirent in garbage_collect_dirent failed: %ld\n", PTR_ERR(new_fd));
@@ -951,7 +938,7 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
951 struct jffs2_raw_inode ri; 938 struct jffs2_raw_inode ri;
952 struct jffs2_node_frag *frag; 939 struct jffs2_node_frag *frag;
953 struct jffs2_full_dnode *new_fn; 940 struct jffs2_full_dnode *new_fn;
954 uint32_t alloclen, phys_ofs, ilen; 941 uint32_t alloclen, ilen;
955 int ret; 942 int ret;
956 943
957 D1(printk(KERN_DEBUG "Writing replacement hole node for ino #%u from offset 0x%x to 0x%x\n", 944 D1(printk(KERN_DEBUG "Writing replacement hole node for ino #%u from offset 0x%x to 0x%x\n",
@@ -1030,14 +1017,14 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
1030 ri.data_crc = cpu_to_je32(0); 1017 ri.data_crc = cpu_to_je32(0);
1031 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); 1018 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
1032 1019
1033 ret = jffs2_reserve_space_gc(c, sizeof(ri), &phys_ofs, &alloclen, 1020 ret = jffs2_reserve_space_gc(c, sizeof(ri), &alloclen,
1034 JFFS2_SUMMARY_INODE_SIZE); 1021 JFFS2_SUMMARY_INODE_SIZE);
1035 if (ret) { 1022 if (ret) {
1036 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_hole failed: %d\n", 1023 printk(KERN_WARNING "jffs2_reserve_space_gc of %zd bytes for garbage_collect_hole failed: %d\n",
1037 sizeof(ri), ret); 1024 sizeof(ri), ret);
1038 return ret; 1025 return ret;
1039 } 1026 }
1040 new_fn = jffs2_write_dnode(c, f, &ri, NULL, 0, phys_ofs, ALLOC_GC); 1027 new_fn = jffs2_write_dnode(c, f, &ri, NULL, 0, ALLOC_GC);
1041 1028
1042 if (IS_ERR(new_fn)) { 1029 if (IS_ERR(new_fn)) {
1043 printk(KERN_WARNING "Error writing new hole node: %ld\n", PTR_ERR(new_fn)); 1030 printk(KERN_WARNING "Error writing new hole node: %ld\n", PTR_ERR(new_fn));
@@ -1099,7 +1086,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1099{ 1086{
1100 struct jffs2_full_dnode *new_fn; 1087 struct jffs2_full_dnode *new_fn;
1101 struct jffs2_raw_inode ri; 1088 struct jffs2_raw_inode ri;
1102 uint32_t alloclen, phys_ofs, offset, orig_end, orig_start; 1089 uint32_t alloclen, offset, orig_end, orig_start;
1103 int ret = 0; 1090 int ret = 0;
1104 unsigned char *comprbuf = NULL, *writebuf; 1091 unsigned char *comprbuf = NULL, *writebuf;
1105 unsigned long pg; 1092 unsigned long pg;
@@ -1256,7 +1243,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1256 uint32_t cdatalen; 1243 uint32_t cdatalen;
1257 uint16_t comprtype = JFFS2_COMPR_NONE; 1244 uint16_t comprtype = JFFS2_COMPR_NONE;
1258 1245
1259 ret = jffs2_reserve_space_gc(c, sizeof(ri) + JFFS2_MIN_DATA_LEN, &phys_ofs, 1246 ret = jffs2_reserve_space_gc(c, sizeof(ri) + JFFS2_MIN_DATA_LEN,
1260 &alloclen, JFFS2_SUMMARY_INODE_SIZE); 1247 &alloclen, JFFS2_SUMMARY_INODE_SIZE);
1261 1248
1262 if (ret) { 1249 if (ret) {
@@ -1293,7 +1280,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1293 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8)); 1280 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
1294 ri.data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); 1281 ri.data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
1295 1282
1296 new_fn = jffs2_write_dnode(c, f, &ri, comprbuf, cdatalen, phys_ofs, ALLOC_GC); 1283 new_fn = jffs2_write_dnode(c, f, &ri, comprbuf, cdatalen, ALLOC_GC);
1297 1284
1298 jffs2_free_comprbuf(comprbuf, writebuf); 1285 jffs2_free_comprbuf(comprbuf, writebuf);
1299 1286
diff --git a/fs/jffs2/nodelist.c b/fs/jffs2/nodelist.c
index 7d563f938b1c..d25d4919ca97 100644
--- a/fs/jffs2/nodelist.c
+++ b/fs/jffs2/nodelist.c
@@ -1048,7 +1048,8 @@ void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
1048} 1048}
1049 1049
1050void jffs2_link_node_ref(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 1050void jffs2_link_node_ref(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
1051 struct jffs2_raw_node_ref *ref, uint32_t len) 1051 struct jffs2_raw_node_ref *ref, uint32_t len,
1052 struct jffs2_inode_cache *ic)
1052{ 1053{
1053 if (!jeb->first_node) 1054 if (!jeb->first_node)
1054 jeb->first_node = ref; 1055 jeb->first_node = ref;
@@ -1065,6 +1066,13 @@ void jffs2_link_node_ref(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
1065 } 1066 }
1066 jeb->last_node = ref; 1067 jeb->last_node = ref;
1067 1068
1069 if (ic) {
1070 ref->next_in_ino = ic->nodes;
1071 ic->nodes = ref;
1072 } else {
1073 ref->next_in_ino = NULL;
1074 }
1075
1068 switch(ref_flags(ref)) { 1076 switch(ref_flags(ref)) {
1069 case REF_UNCHECKED: 1077 case REF_UNCHECKED:
1070 c->unchecked_size += len; 1078 c->unchecked_size += len;
@@ -1120,12 +1128,11 @@ int jffs2_scan_dirty_space(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
1120 1128
1121 ref->flash_offset = jeb->offset + c->sector_size - jeb->free_size; 1129 ref->flash_offset = jeb->offset + c->sector_size - jeb->free_size;
1122 ref->flash_offset |= REF_OBSOLETE; 1130 ref->flash_offset |= REF_OBSOLETE;
1123 ref->next_in_ino = 0;
1124#ifdef TEST_TOTLEN 1131#ifdef TEST_TOTLEN
1125 ref->__totlen = size; 1132 ref->__totlen = size;
1126#endif 1133#endif
1127 1134
1128 jffs2_link_node_ref(c, jeb, ref, size); 1135 jffs2_link_node_ref(c, jeb, ref, size, NULL);
1129 } 1136 }
1130 1137
1131 return 0; 1138 return 0;
diff --git a/fs/jffs2/nodelist.h b/fs/jffs2/nodelist.h
index 80d1fda2212b..76f1b9419eea 100644
--- a/fs/jffs2/nodelist.h
+++ b/fs/jffs2/nodelist.h
@@ -77,9 +77,9 @@
77struct jffs2_raw_node_ref 77struct jffs2_raw_node_ref
78{ 78{
79 struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref 79 struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref
80 for this inode. If this is the last, it points to the inode_cache 80 for this object. If this _is_ the last, it points to the inode_cache,
81 for this inode instead. The inode_cache will have NULL in the first 81 xattr_ref or xattr_datum instead. The common part of those structures
82 word so you know when you've got there :) */ 82 has NULL in the first word. See jffs2_raw_ref_to_ic() below */
83 struct jffs2_raw_node_ref *next_phys; 83 struct jffs2_raw_node_ref *next_phys;
84 uint32_t flash_offset; 84 uint32_t flash_offset;
85#define TEST_TOTLEN 85#define TEST_TOTLEN
@@ -88,6 +88,18 @@ struct jffs2_raw_node_ref
88#endif 88#endif
89}; 89};
90 90
91static inline struct jffs2_inode_cache *jffs2_raw_ref_to_ic(struct jffs2_raw_node_ref *raw)
92{
93 while(raw->next_in_ino) {
94 raw = raw->next_in_ino;
95 }
96
97 /* NB. This can be a jffs2_xattr_datum or jffs2_xattr_ref and
98 not actually a jffs2_inode_cache. Check ->class */
99 return ((struct jffs2_inode_cache *)raw);
100}
101
102
91 /* flash_offset & 3 always has to be zero, because nodes are 103 /* flash_offset & 3 always has to be zero, because nodes are
92 always aligned at 4 bytes. So we have a couple of extra bits 104 always aligned at 4 bytes. So we have a couple of extra bits
93 to play with, which indicate the node's status; see below: */ 105 to play with, which indicate the node's status; see below: */
@@ -113,20 +125,27 @@ struct jffs2_raw_node_ref
113 a pointer to the first physical node which is part of this inode, too. 125 a pointer to the first physical node which is part of this inode, too.
114*/ 126*/
115struct jffs2_inode_cache { 127struct jffs2_inode_cache {
128 /* First part of structure is shared with other objects which
129 can terminate the raw node refs' next_in_ino list -- which
130 currently struct jffs2_xattr_datum and struct jffs2_xattr_ref. */
131
116 struct jffs2_full_dirent *scan_dents; /* Used during scan to hold 132 struct jffs2_full_dirent *scan_dents; /* Used during scan to hold
117 temporary lists of dirents, and later must be set to 133 temporary lists of dirents, and later must be set to
118 NULL to mark the end of the raw_node_ref->next_in_ino 134 NULL to mark the end of the raw_node_ref->next_in_ino
119 chain. */ 135 chain. */
120 u8 class; /* It's used for identification */
121 u8 flags;
122 uint16_t state;
123 struct jffs2_inode_cache *next;
124 struct jffs2_raw_node_ref *nodes; 136 struct jffs2_raw_node_ref *nodes;
137 uint8_t class; /* It's used for identification */
138
139 /* end of shared structure */
140
141 uint8_t flags;
142 uint16_t state;
125 uint32_t ino; 143 uint32_t ino;
126 int nlink; 144 struct jffs2_inode_cache *next;
127#ifdef CONFIG_JFFS2_FS_XATTR 145#ifdef CONFIG_JFFS2_FS_XATTR
128 struct jffs2_xattr_ref *xref; 146 struct jffs2_xattr_ref *xref;
129#endif 147#endif
148 int nlink;
130}; 149};
131 150
132/* Inode states for 'state' above. We need the 'GC' state to prevent 151/* Inode states for 'state' above. We need the 'GC' state to prevent
@@ -148,6 +167,8 @@ struct jffs2_inode_cache {
148 167
149#define INOCACHE_HASHSIZE 128 168#define INOCACHE_HASHSIZE 128
150 169
170#define write_ofs(c) ((c)->nextblock->offset + (c)->sector_size - (c)->nextblock->free_size)
171
151/* 172/*
152 Larger representation of a raw node, kept in-core only when the 173 Larger representation of a raw node, kept in-core only when the
153 struct inode for this particular ino is instantiated. 174 struct inode for this particular ino is instantiated.
@@ -250,15 +271,6 @@ static inline int jffs2_encode_dev(union jffs2_device_node *jdev, dev_t rdev)
250 } 271 }
251} 272}
252 273
253static inline struct jffs2_inode_cache *jffs2_raw_ref_to_ic(struct jffs2_raw_node_ref *raw)
254{
255 while(raw->next_in_ino) {
256 raw = raw->next_in_ino;
257 }
258
259 return ((struct jffs2_inode_cache *)raw);
260}
261
262static inline struct jffs2_node_frag *frag_first(struct rb_root *root) 274static inline struct jffs2_node_frag *frag_first(struct rb_root *root)
263{ 275{
264 struct rb_node *node = root->rb_node; 276 struct rb_node *node = root->rb_node;
@@ -307,32 +319,43 @@ int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_in
307void jffs2_truncate_fragtree (struct jffs2_sb_info *c, struct rb_root *list, uint32_t size); 319void jffs2_truncate_fragtree (struct jffs2_sb_info *c, struct rb_root *list, uint32_t size);
308int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_tmp_dnode_info *tn); 320int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_tmp_dnode_info *tn);
309void jffs2_link_node_ref(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, 321void jffs2_link_node_ref(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
310 struct jffs2_raw_node_ref *ref, uint32_t len); 322 struct jffs2_raw_node_ref *ref, uint32_t len,
323 struct jffs2_inode_cache *ic);
311extern uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, 324extern uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c,
312 struct jffs2_eraseblock *jeb, 325 struct jffs2_eraseblock *jeb,
313 struct jffs2_raw_node_ref *ref); 326 struct jffs2_raw_node_ref *ref);
314 327
315/* nodemgmt.c */ 328/* nodemgmt.c */
316int jffs2_thread_should_wake(struct jffs2_sb_info *c); 329int jffs2_thread_should_wake(struct jffs2_sb_info *c);
317int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, 330int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
318 uint32_t *len, int prio, uint32_t sumsize); 331 uint32_t *len, int prio, uint32_t sumsize);
319int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, 332int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
320 uint32_t *len, uint32_t sumsize); 333 uint32_t *len, uint32_t sumsize);
321int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new, uint32_t len); 334int jffs2_add_physical_node_ref(struct jffs2_sb_info *c,
335 struct jffs2_raw_node_ref *new,
336 uint32_t len,
337 struct jffs2_inode_cache *ic);
322void jffs2_complete_reservation(struct jffs2_sb_info *c); 338void jffs2_complete_reservation(struct jffs2_sb_info *c);
323void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *raw); 339void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *raw);
324 340
325/* write.c */ 341/* write.c */
326int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri); 342int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri);
327 343
328struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode); 344struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
329struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs, int alloc_mode); 345 struct jffs2_raw_inode *ri, const unsigned char *data,
346 uint32_t datalen, int alloc_mode);
347struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
348 struct jffs2_raw_dirent *rd, const unsigned char *name,
349 uint32_t namelen, int alloc_mode);
330int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 350int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
331 struct jffs2_raw_inode *ri, unsigned char *buf, 351 struct jffs2_raw_inode *ri, unsigned char *buf,
332 uint32_t offset, uint32_t writelen, uint32_t *retlen); 352 uint32_t offset, uint32_t writelen, uint32_t *retlen);
333int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const char *name, int namelen); 353int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f,
334int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name, int namelen, struct jffs2_inode_info *dead_f, uint32_t time); 354 struct jffs2_raw_inode *ri, const char *name, int namelen);
335int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino, uint8_t type, const char *name, int namelen, uint32_t time); 355int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name,
356 int namelen, struct jffs2_inode_info *dead_f, uint32_t time);
357int jffs2_do_link(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino,
358 uint8_t type, const char *name, int namelen, uint32_t time);
336 359
337 360
338/* readinode.c */ 361/* readinode.c */
diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c
index 9a0f312cfcda..8feb8749bc75 100644
--- a/fs/jffs2/nodemgmt.c
+++ b/fs/jffs2/nodemgmt.c
@@ -23,13 +23,12 @@
23 * jffs2_reserve_space - request physical space to write nodes to flash 23 * jffs2_reserve_space - request physical space to write nodes to flash
24 * @c: superblock info 24 * @c: superblock info
25 * @minsize: Minimum acceptable size of allocation 25 * @minsize: Minimum acceptable size of allocation
26 * @ofs: Returned value of node offset
27 * @len: Returned value of allocation length 26 * @len: Returned value of allocation length
28 * @prio: Allocation type - ALLOC_{NORMAL,DELETION} 27 * @prio: Allocation type - ALLOC_{NORMAL,DELETION}
29 * 28 *
30 * Requests a block of physical space on the flash. Returns zero for success 29 * Requests a block of physical space on the flash. Returns zero for success
31 * and puts 'ofs' and 'len' into the appriopriate place, or returns -ENOSPC 30 * and puts 'len' into the appropriate place, or returns -ENOSPC or other
32 * or other error if appropriate. 31 * error if appropriate. Doesn't return len since that's
33 * 32 *
34 * If it returns zero, jffs2_reserve_space() also downs the per-filesystem 33 * If it returns zero, jffs2_reserve_space() also downs the per-filesystem
35 * allocation semaphore, to prevent more than one allocation from being 34 * allocation semaphore, to prevent more than one allocation from being
@@ -40,9 +39,9 @@
40 */ 39 */
41 40
42static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, 41static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
43 uint32_t *ofs, uint32_t *len, uint32_t sumsize); 42 uint32_t *len, uint32_t sumsize);
44 43
45int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, 44int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
46 uint32_t *len, int prio, uint32_t sumsize) 45 uint32_t *len, int prio, uint32_t sumsize)
47{ 46{
48 int ret = -EAGAIN; 47 int ret = -EAGAIN;
@@ -132,7 +131,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs
132 spin_lock(&c->erase_completion_lock); 131 spin_lock(&c->erase_completion_lock);
133 } 132 }
134 133
135 ret = jffs2_do_reserve_space(c, minsize, ofs, len, sumsize); 134 ret = jffs2_do_reserve_space(c, minsize, len, sumsize);
136 if (ret) { 135 if (ret) {
137 D1(printk(KERN_DEBUG "jffs2_reserve_space: ret is %d\n", ret)); 136 D1(printk(KERN_DEBUG "jffs2_reserve_space: ret is %d\n", ret));
138 } 137 }
@@ -143,8 +142,8 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs
143 return ret; 142 return ret;
144} 143}
145 144
146int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, 145int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
147 uint32_t *len, uint32_t sumsize) 146 uint32_t *len, uint32_t sumsize)
148{ 147{
149 int ret = -EAGAIN; 148 int ret = -EAGAIN;
150 minsize = PAD(minsize); 149 minsize = PAD(minsize);
@@ -153,7 +152,7 @@ int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *
153 152
154 spin_lock(&c->erase_completion_lock); 153 spin_lock(&c->erase_completion_lock);
155 while(ret == -EAGAIN) { 154 while(ret == -EAGAIN) {
156 ret = jffs2_do_reserve_space(c, minsize, ofs, len, sumsize); 155 ret = jffs2_do_reserve_space(c, minsize, len, sumsize);
157 if (ret) { 156 if (ret) {
158 D1(printk(KERN_DEBUG "jffs2_reserve_space_gc: looping, ret is %d\n", ret)); 157 D1(printk(KERN_DEBUG "jffs2_reserve_space_gc: looping, ret is %d\n", ret));
159 } 158 }
@@ -259,10 +258,11 @@ static int jffs2_find_nextblock(struct jffs2_sb_info *c)
259} 258}
260 259
261/* Called with alloc sem _and_ erase_completion_lock */ 260/* Called with alloc sem _and_ erase_completion_lock */
262static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uint32_t *ofs, uint32_t *len, uint32_t sumsize) 261static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
262 uint32_t *len, uint32_t sumsize)
263{ 263{
264 struct jffs2_eraseblock *jeb = c->nextblock; 264 struct jffs2_eraseblock *jeb = c->nextblock;
265 uint32_t reserved_size; /* for summary information at the end of the jeb */ 265 uint32_t reserved_size; /* for summary information at the end of the jeb */
266 int ret; 266 int ret;
267 267
268 restart: 268 restart:
@@ -349,7 +349,6 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uin
349 } 349 }
350 /* OK, jeb (==c->nextblock) is now pointing at a block which definitely has 350 /* OK, jeb (==c->nextblock) is now pointing at a block which definitely has
351 enough space */ 351 enough space */
352 *ofs = jeb->offset + (c->sector_size - jeb->free_size);
353 *len = jeb->free_size - reserved_size; 352 *len = jeb->free_size - reserved_size;
354 353
355 if (c->cleanmarker_size && jeb->used_size == c->cleanmarker_size && 354 if (c->cleanmarker_size && jeb->used_size == c->cleanmarker_size &&
@@ -365,7 +364,8 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uin
365 spin_lock(&c->erase_completion_lock); 364 spin_lock(&c->erase_completion_lock);
366 } 365 }
367 366
368 D1(printk(KERN_DEBUG "jffs2_do_reserve_space(): Giving 0x%x bytes at 0x%x\n", *len, *ofs)); 367 D1(printk(KERN_DEBUG "jffs2_do_reserve_space(): Giving 0x%x bytes at 0x%x\n",
368 *len, jeb->offset + (c->sector_size - jeb->free_size)));
369 return 0; 369 return 0;
370} 370}
371 371
@@ -381,7 +381,8 @@ static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, uin
381 * Must be called with the alloc_sem held. 381 * Must be called with the alloc_sem held.
382 */ 382 */
383 383
384int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new, uint32_t len) 384int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new,
385 uint32_t len, struct jffs2_inode_cache *ic)
385{ 386{
386 struct jffs2_eraseblock *jeb; 387 struct jffs2_eraseblock *jeb;
387 388
@@ -403,7 +404,7 @@ int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_r
403#endif 404#endif
404 spin_lock(&c->erase_completion_lock); 405 spin_lock(&c->erase_completion_lock);
405 406
406 jffs2_link_node_ref(c, jeb, new, len); 407 jffs2_link_node_ref(c, jeb, new, len, ic);
407 408
408 if (!jeb->free_size && !jeb->dirty_size && !ISDIRTY(jeb->wasted_size)) { 409 if (!jeb->free_size && !jeb->dirty_size && !ISDIRTY(jeb->wasted_size)) {
409 /* If it lives on the dirty_list, jffs2_reserve_space will put it there */ 410 /* If it lives on the dirty_list, jffs2_reserve_space will put it there */
@@ -660,6 +661,10 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
660 spin_lock(&c->erase_completion_lock); 661 spin_lock(&c->erase_completion_lock);
661 662
662 ic = jffs2_raw_ref_to_ic(ref); 663 ic = jffs2_raw_ref_to_ic(ref);
664 /* It seems we should never call jffs2_mark_node_obsolete() for
665 XATTR nodes.... yet. Make sure we notice if/when we change
666 that :) */
667 BUG_ON(ic->class != RAWNODE_CLASS_INODE_CACHE);
663 for (p = &ic->nodes; (*p) != ref; p = &((*p)->next_in_ino)) 668 for (p = &ic->nodes; (*p) != ref; p = &((*p)->next_in_ino))
664 ; 669 ;
665 670
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
index d2ad2a2081d8..743c9e52152d 100644
--- a/fs/jffs2/os-linux.h
+++ b/fs/jffs2/os-linux.h
@@ -92,11 +92,7 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
92#define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e) 92#define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e)
93#define jffs2_wbuf_timeout NULL 93#define jffs2_wbuf_timeout NULL
94#define jffs2_wbuf_process NULL 94#define jffs2_wbuf_process NULL
95#define jffs2_nor_ecc(c) (0)
96#define jffs2_dataflash(c) (0) 95#define jffs2_dataflash(c) (0)
97#define jffs2_nor_wbuf_flash(c) (0)
98#define jffs2_nor_ecc_flash_setup(c) (0)
99#define jffs2_nor_ecc_flash_cleanup(c) do {} while (0)
100#define jffs2_dataflash_setup(c) (0) 96#define jffs2_dataflash_setup(c) (0)
101#define jffs2_dataflash_cleanup(c) do {} while (0) 97#define jffs2_dataflash_cleanup(c) do {} while (0)
102#define jffs2_nor_wbuf_flash_setup(c) (0) 98#define jffs2_nor_wbuf_flash_setup(c) (0)
@@ -109,9 +105,7 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
109#ifdef CONFIG_JFFS2_SUMMARY 105#ifdef CONFIG_JFFS2_SUMMARY
110#define jffs2_can_mark_obsolete(c) (0) 106#define jffs2_can_mark_obsolete(c) (0)
111#else 107#else
112#define jffs2_can_mark_obsolete(c) \ 108#define jffs2_can_mark_obsolete(c) (c->mtd->flags & (MTD_BIT_WRITEABLE))
113 ((c->mtd->type == MTD_NORFLASH && !(c->mtd->flags & (MTD_ECC|MTD_PROGRAM_REGIONS))) || \
114 c->mtd->type == MTD_RAM)
115#endif 109#endif
116 110
117#define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH) 111#define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH)
@@ -135,15 +129,11 @@ int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c);
135int jffs2_nand_flash_setup(struct jffs2_sb_info *c); 129int jffs2_nand_flash_setup(struct jffs2_sb_info *c);
136void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c); 130void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c);
137 131
138#define jffs2_nor_ecc(c) (c->mtd->type == MTD_NORFLASH && (c->mtd->flags & MTD_ECC))
139int jffs2_nor_ecc_flash_setup(struct jffs2_sb_info *c);
140void jffs2_nor_ecc_flash_cleanup(struct jffs2_sb_info *c);
141
142#define jffs2_dataflash(c) (c->mtd->type == MTD_DATAFLASH) 132#define jffs2_dataflash(c) (c->mtd->type == MTD_DATAFLASH)
143int jffs2_dataflash_setup(struct jffs2_sb_info *c); 133int jffs2_dataflash_setup(struct jffs2_sb_info *c);
144void jffs2_dataflash_cleanup(struct jffs2_sb_info *c); 134void jffs2_dataflash_cleanup(struct jffs2_sb_info *c);
145 135
146#define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && (c->mtd->flags & MTD_PROGRAM_REGIONS)) 136#define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && ! (c->mtd->flags & MTD_BIT_WRITEABLE))
147int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c); 137int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c);
148void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c); 138void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c);
149 139
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index cffafec01e48..6fce703c0543 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -361,9 +361,9 @@ static int jffs2_scan_xattr_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
361 xd->node = raw; 361 xd->node = raw;
362 362
363 raw->flash_offset = ofs | REF_PRISTINE; 363 raw->flash_offset = ofs | REF_PRISTINE;
364 raw->next_in_ino = (void *)xd;
365 364
366 jffs2_link_node_ref(c, jeb, raw, totlen); 365 jffs2_link_node_ref(c, jeb, raw, totlen, NULL);
366 /* FIXME */ raw->next_in_ino = (void *)xd;
367 367
368 if (jffs2_sum_active()) 368 if (jffs2_sum_active())
369 jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset); 369 jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset);
@@ -425,9 +425,9 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
425 c->xref_temp = ref; 425 c->xref_temp = ref;
426 426
427 raw->flash_offset = ofs | REF_PRISTINE; 427 raw->flash_offset = ofs | REF_PRISTINE;
428 raw->next_in_ino = (void *)ref;
429 428
430 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(rr->totlen))); 429 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(rr->totlen)), NULL);
430 /* FIXME */ raw->next_in_ino = (void *)ref;
431 431
432 if (jffs2_sum_active()) 432 if (jffs2_sum_active())
433 jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset); 433 jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset);
@@ -844,10 +844,9 @@ scan_more:
844 printk(KERN_NOTICE "Failed to allocate node ref for clean marker\n"); 844 printk(KERN_NOTICE "Failed to allocate node ref for clean marker\n");
845 return -ENOMEM; 845 return -ENOMEM;
846 } 846 }
847 marker_ref->next_in_ino = NULL;
848 marker_ref->flash_offset = ofs | REF_NORMAL; 847 marker_ref->flash_offset = ofs | REF_NORMAL;
849 848
850 jffs2_link_node_ref(c, jeb, marker_ref, c->cleanmarker_size); 849 jffs2_link_node_ref(c, jeb, marker_ref, c->cleanmarker_size, NULL);
851 850
852 ofs += PAD(c->cleanmarker_size); 851 ofs += PAD(c->cleanmarker_size);
853 } 852 }
@@ -892,8 +891,7 @@ scan_more:
892 if (!ref) 891 if (!ref)
893 return -ENOMEM; 892 return -ENOMEM;
894 ref->flash_offset = ofs | REF_PRISTINE; 893 ref->flash_offset = ofs | REF_PRISTINE;
895 ref->next_in_ino = 0; 894 jffs2_link_node_ref(c, jeb, ref, PAD(je32_to_cpu(node->totlen)), NULL);
896 jffs2_link_node_ref(c, jeb, ref, PAD(je32_to_cpu(node->totlen)));
897 895
898 /* We can't summarise nodes we don't grok */ 896 /* We can't summarise nodes we don't grok */
899 jffs2_sum_disable_collecting(s); 897 jffs2_sum_disable_collecting(s);
@@ -1004,10 +1002,7 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
1004 1002
1005 raw->flash_offset = ofs | REF_UNCHECKED; 1003 raw->flash_offset = ofs | REF_UNCHECKED;
1006 1004
1007 raw->next_in_ino = ic->nodes; 1005 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(ri->totlen)), ic);
1008 ic->nodes = raw;
1009
1010 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(ri->totlen)));
1011 1006
1012 D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n", 1007 D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n",
1013 je32_to_cpu(ri->ino), je32_to_cpu(ri->version), 1008 je32_to_cpu(ri->ino), je32_to_cpu(ri->version),
@@ -1082,10 +1077,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
1082 } 1077 }
1083 1078
1084 raw->flash_offset = ofs | REF_PRISTINE; 1079 raw->flash_offset = ofs | REF_PRISTINE;
1085 raw->next_in_ino = ic->nodes; 1080 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(rd->totlen)), ic);
1086 ic->nodes = raw;
1087
1088 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(rd->totlen)));
1089 1081
1090 fd->raw = raw; 1082 fd->raw = raw;
1091 fd->next = NULL; 1083 fd->next = NULL;
diff --git a/fs/jffs2/summary.c b/fs/jffs2/summary.c
index 1451732e1fa7..351ba9f8185e 100644
--- a/fs/jffs2/summary.c
+++ b/fs/jffs2/summary.c
@@ -430,10 +430,7 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
430 430
431 raw->flash_offset |= REF_UNCHECKED; 431 raw->flash_offset |= REF_UNCHECKED;
432 432
433 raw->next_in_ino = ic->nodes; 433 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spi->totlen)), ic);
434 ic->nodes = raw;
435
436 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spi->totlen)));
437 434
438 *pseudo_random += je32_to_cpu(spi->version); 435 *pseudo_random += je32_to_cpu(spi->version);
439 436
@@ -473,10 +470,7 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
473 } 470 }
474 471
475 raw->flash_offset |= REF_PRISTINE; 472 raw->flash_offset |= REF_PRISTINE;
476 raw->next_in_ino = ic->nodes; 473 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spd->totlen)), ic);
477 ic->nodes = raw;
478
479 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spd->totlen)));
480 474
481 fd->raw = raw; 475 fd->raw = raw;
482 fd->next = NULL; 476 fd->next = NULL;
@@ -525,9 +519,9 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
525 xd->node = raw; 519 xd->node = raw;
526 520
527 raw->flash_offset |= REF_UNCHECKED; 521 raw->flash_offset |= REF_UNCHECKED;
528 raw->next_in_ino = (void *)xd;
529 522
530 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spx->totlen))); 523 jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spx->totlen)), NULL);
524 /* FIXME */ raw->next_in_ino = (void *)xd;
531 525
532 *pseudo_random += je32_to_cpu(spx->xid); 526 *pseudo_random += je32_to_cpu(spx->xid);
533 sp += JFFS2_SUMMARY_XATTR_SIZE; 527 sp += JFFS2_SUMMARY_XATTR_SIZE;
@@ -561,9 +555,9 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
561 c->xref_temp = ref; 555 c->xref_temp = ref;
562 556
563 raw->flash_offset |= REF_UNCHECKED; 557 raw->flash_offset |= REF_UNCHECKED;
564 raw->next_in_ino = (void *)ref;
565 558
566 jffs2_link_node_ref(c, jeb, raw, PAD(sizeof(struct jffs2_raw_xref))); 559 jffs2_link_node_ref(c, jeb, raw, PAD(sizeof(struct jffs2_raw_xref)), NULL);
560 /* FIXME */ raw->next_in_ino = (void *)ref;
567 561
568 *pseudo_random += raw->flash_offset; 562 *pseudo_random += raw->flash_offset;
569 sp += JFFS2_SUMMARY_XREF_SIZE; 563 sp += JFFS2_SUMMARY_XREF_SIZE;
@@ -664,9 +658,8 @@ int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
664 } 658 }
665 659
666 marker_ref->flash_offset = jeb->offset | REF_NORMAL; 660 marker_ref->flash_offset = jeb->offset | REF_NORMAL;
667 marker_ref->next_in_ino = NULL;
668 661
669 jffs2_link_node_ref(c, jeb, marker_ref, je32_to_cpu(summary->cln_mkr)); 662 jffs2_link_node_ref(c, jeb, marker_ref, je32_to_cpu(summary->cln_mkr), NULL);
670 } 663 }
671 } 664 }
672 665
@@ -686,10 +679,9 @@ int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
686 return -ENOMEM; 679 return -ENOMEM;
687 } 680 }
688 681
689 cache_ref->next_in_ino = NULL;
690 cache_ref->flash_offset |= REF_NORMAL; 682 cache_ref->flash_offset |= REF_NORMAL;
691 683
692 jffs2_link_node_ref(c, jeb, cache_ref, sumsize); 684 jffs2_link_node_ref(c, jeb, cache_ref, sumsize, NULL);
693 685
694 if (unlikely(jeb->free_size)) { 686 if (unlikely(jeb->free_size)) {
695 JFFS2_WARNING("Free size 0x%x bytes in eraseblock @0x%08x with summary?\n", 687 JFFS2_WARNING("Free size 0x%x bytes in eraseblock @0x%08x with summary?\n",
@@ -849,9 +841,8 @@ static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock
849 841
850 ref->flash_offset = jeb->offset + c->sector_size - jeb->free_size; 842 ref->flash_offset = jeb->offset + c->sector_size - jeb->free_size;
851 ref->flash_offset |= REF_OBSOLETE; 843 ref->flash_offset |= REF_OBSOLETE;
852 ref->next_in_ino = 0;
853 844
854 jffs2_link_node_ref(c, jeb, ref, c->sector_size - jeb->free_size); 845 jffs2_link_node_ref(c, jeb, ref, c->sector_size - jeb->free_size, NULL);
855 } 846 }
856 847
857 c->summary->sum_size = JFFS2_SUMMARY_NOSUM_SIZE; 848 c->summary->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
@@ -909,11 +900,10 @@ int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
909 return -ENOMEM; 900 return -ENOMEM;
910 } 901 }
911 902
912 summary_ref->next_in_ino = NULL;
913 summary_ref->flash_offset = (jeb->offset + c->sector_size - jeb->free_size) | REF_NORMAL; 903 summary_ref->flash_offset = (jeb->offset + c->sector_size - jeb->free_size) | REF_NORMAL;
914 904
915 spin_lock(&c->erase_completion_lock); 905 spin_lock(&c->erase_completion_lock);
916 jffs2_link_node_ref(c, jeb, summary_ref, infosize); 906 jffs2_link_node_ref(c, jeb, summary_ref, infosize, NULL);
917 907
918 return 0; 908 return 0;
919} 909}
diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index 0442a5753d33..916c87d3393b 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -265,12 +265,14 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
265 265
266 266
267 /* ... and get an allocation of space from a shiny new block instead */ 267 /* ... and get an allocation of space from a shiny new block instead */
268 ret = jffs2_reserve_space_gc(c, end-start, &ofs, &len, JFFS2_SUMMARY_NOSUM_SIZE); 268 ret = jffs2_reserve_space_gc(c, end-start, &len, JFFS2_SUMMARY_NOSUM_SIZE);
269 if (ret) { 269 if (ret) {
270 printk(KERN_WARNING "Failed to allocate space for wbuf recovery. Data loss ensues.\n"); 270 printk(KERN_WARNING "Failed to allocate space for wbuf recovery. Data loss ensues.\n");
271 kfree(buf); 271 kfree(buf);
272 return; 272 return;
273 } 273 }
274 ofs = write_ofs(c);
275
274 if (end-start >= c->wbuf_pagesize) { 276 if (end-start >= c->wbuf_pagesize) {
275 /* Need to do another write immediately, but it's possible 277 /* Need to do another write immediately, but it's possible
276 that this is just because the wbuf itself is completely 278 that this is just because the wbuf itself is completely
@@ -312,9 +314,8 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
312 return; 314 return;
313 315
314 raw2->flash_offset = ofs | REF_OBSOLETE; 316 raw2->flash_offset = ofs | REF_OBSOLETE;
315 raw2->next_in_ino = NULL;
316 317
317 jffs2_add_physical_node_ref(c, raw2, ref_totlen(c, jeb, *first_raw)); 318 jffs2_add_physical_node_ref(c, raw2, ref_totlen(c, jeb, *first_raw), NULL);
318 } 319 }
319 return; 320 return;
320 } 321 }
@@ -507,11 +508,10 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
507 return -ENOMEM; 508 return -ENOMEM;
508 ref->flash_offset = c->wbuf_ofs + c->wbuf_len; 509 ref->flash_offset = c->wbuf_ofs + c->wbuf_len;
509 ref->flash_offset |= REF_OBSOLETE; 510 ref->flash_offset |= REF_OBSOLETE;
510 ref->next_in_ino = NULL;
511 511
512 spin_lock(&c->erase_completion_lock); 512 spin_lock(&c->erase_completion_lock);
513 513
514 jffs2_link_node_ref(c, jeb, ref, waste); 514 jffs2_link_node_ref(c, jeb, ref, waste, NULL);
515 /* FIXME: that made it count as dirty. Convert to wasted */ 515 /* FIXME: that made it count as dirty. Convert to wasted */
516 jeb->dirty_size -= waste; 516 jeb->dirty_size -= waste;
517 c->dirty_size -= waste; 517 c->dirty_size -= waste;
@@ -650,19 +650,6 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs,
650 } 650 }
651 651
652 /* 652 /*
653 * Fixup the wbuf if we are moving to a new eraseblock. The
654 * checks below fail for ECC'd NOR because cleanmarker == 16,
655 * so a block starts at xxx0010.
656 */
657 if (jffs2_nor_ecc(c)) {
658 if (((c->wbuf_ofs % c->sector_size) == 0) && !c->wbuf_len) {
659 c->wbuf_ofs = PAGE_DIV(to);
660 c->wbuf_len = PAGE_MOD(to);
661 memset(c->wbuf,0xff,c->wbuf_pagesize);
662 }
663 }
664
665 /*
666 * Sanity checks on target address. It's permitted to write 653 * Sanity checks on target address. It's permitted to write
667 * at PAD(c->wbuf_len+c->wbuf_ofs), and it's permitted to 654 * at PAD(c->wbuf_len+c->wbuf_ofs), and it's permitted to
668 * write at the beginning of a new erase block. Anything else, 655 * write at the beginning of a new erase block. Anything else,
@@ -1107,7 +1094,7 @@ int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
1107 1094
1108 /* Initialise write buffer */ 1095 /* Initialise write buffer */
1109 init_rwsem(&c->wbuf_sem); 1096 init_rwsem(&c->wbuf_sem);
1110 c->wbuf_pagesize = c->mtd->oobblock; 1097 c->wbuf_pagesize = c->mtd->writesize;
1111 c->wbuf_ofs = 0xFFFFFFFF; 1098 c->wbuf_ofs = 0xFFFFFFFF;
1112 1099
1113 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL); 1100 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
@@ -1178,33 +1165,14 @@ void jffs2_dataflash_cleanup(struct jffs2_sb_info *c) {
1178 kfree(c->wbuf); 1165 kfree(c->wbuf);
1179} 1166}
1180 1167
1181int jffs2_nor_ecc_flash_setup(struct jffs2_sb_info *c) {
1182 /* Cleanmarker is actually larger on the flashes */
1183 c->cleanmarker_size = 16;
1184
1185 /* Initialize write buffer */
1186 init_rwsem(&c->wbuf_sem);
1187 c->wbuf_pagesize = c->mtd->eccsize;
1188 c->wbuf_ofs = 0xFFFFFFFF;
1189
1190 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
1191 if (!c->wbuf)
1192 return -ENOMEM;
1193
1194 return 0;
1195}
1196
1197void jffs2_nor_ecc_flash_cleanup(struct jffs2_sb_info *c) {
1198 kfree(c->wbuf);
1199}
1200
1201int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c) { 1168int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c) {
1202 /* Cleanmarker currently occupies a whole programming region */ 1169 /* Cleanmarker currently occupies whole programming regions,
1203 c->cleanmarker_size = MTD_PROGREGION_SIZE(c->mtd); 1170 * either one or 2 for 8Byte STMicro flashes. */
1171 c->cleanmarker_size = max(16u, c->mtd->writesize);
1204 1172
1205 /* Initialize write buffer */ 1173 /* Initialize write buffer */
1206 init_rwsem(&c->wbuf_sem); 1174 init_rwsem(&c->wbuf_sem);
1207 c->wbuf_pagesize = MTD_PROGREGION_SIZE(c->mtd); 1175 c->wbuf_pagesize = c->mtd->writesize;
1208 c->wbuf_ofs = 0xFFFFFFFF; 1176 c->wbuf_ofs = 0xFFFFFFFF;
1209 1177
1210 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL); 1178 c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c
index 4462541d11f8..0e12b7561b71 100644
--- a/fs/jffs2/write.c
+++ b/fs/jffs2/write.c
@@ -56,12 +56,15 @@ int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint
56/* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it, 56/* jffs2_write_dnode - given a raw_inode, allocate a full_dnode for it,
57 write it to the flash, link it into the existing inode/fragment list */ 57 write it to the flash, link it into the existing inode/fragment list */
58 58
59struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_inode *ri, const unsigned char *data, uint32_t datalen, uint32_t flash_ofs, int alloc_mode) 59struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
60 struct jffs2_raw_inode *ri, const unsigned char *data,
61 uint32_t datalen, int alloc_mode)
60 62
61{ 63{
62 struct jffs2_raw_node_ref *raw; 64 struct jffs2_raw_node_ref *raw;
63 struct jffs2_full_dnode *fn; 65 struct jffs2_full_dnode *fn;
64 size_t retlen; 66 size_t retlen;
67 uint32_t flash_ofs;
65 struct kvec vecs[2]; 68 struct kvec vecs[2];
66 int ret; 69 int ret;
67 int retried = 0; 70 int retried = 0;
@@ -77,8 +80,6 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
77 vecs[1].iov_base = (unsigned char *)data; 80 vecs[1].iov_base = (unsigned char *)data;
78 vecs[1].iov_len = datalen; 81 vecs[1].iov_len = datalen;
79 82
80 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
81
82 if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) { 83 if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) {
83 printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08zx) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen); 84 printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08zx) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen);
84 } 85 }
@@ -102,7 +103,9 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
102 retry: 103 retry:
103 fn->raw = raw; 104 fn->raw = raw;
104 105
105 raw->flash_offset = flash_ofs; 106 raw->flash_offset = flash_ofs = write_ofs(c);
107
108 jffs2_dbg_prewrite_paranoia_check(c, flash_ofs, vecs[0].iov_len + vecs[1].iov_len);
106 109
107 if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) { 110 if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) {
108 BUG_ON(!retried); 111 BUG_ON(!retried);
@@ -122,16 +125,13 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
122 125
123 /* Mark the space as dirtied */ 126 /* Mark the space as dirtied */
124 if (retlen) { 127 if (retlen) {
125 /* Doesn't belong to any inode */
126 raw->next_in_ino = NULL;
127
128 /* Don't change raw->size to match retlen. We may have 128 /* Don't change raw->size to match retlen. We may have
129 written the node header already, and only the data will 129 written the node header already, and only the data will
130 seem corrupted, in which case the scan would skip over 130 seem corrupted, in which case the scan would skip over
131 any node we write before the original intended end of 131 any node we write before the original intended end of
132 this node */ 132 this node */
133 raw->flash_offset |= REF_OBSOLETE; 133 raw->flash_offset |= REF_OBSOLETE;
134 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(*ri)+datalen)); 134 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(*ri)+datalen), NULL);
135 jffs2_mark_node_obsolete(c, raw); 135 jffs2_mark_node_obsolete(c, raw);
136 } else { 136 } else {
137 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset); 137 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset);
@@ -150,19 +150,20 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
150 jffs2_dbg_acct_paranoia_check(c, jeb); 150 jffs2_dbg_acct_paranoia_check(c, jeb);
151 151
152 if (alloc_mode == ALLOC_GC) { 152 if (alloc_mode == ALLOC_GC) {
153 ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs, 153 ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &dummy,
154 &dummy, JFFS2_SUMMARY_INODE_SIZE); 154 JFFS2_SUMMARY_INODE_SIZE);
155 } else { 155 } else {
156 /* Locking pain */ 156 /* Locking pain */
157 up(&f->sem); 157 up(&f->sem);
158 jffs2_complete_reservation(c); 158 jffs2_complete_reservation(c);
159 159
160 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs, 160 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &dummy,
161 &dummy, alloc_mode, JFFS2_SUMMARY_INODE_SIZE); 161 alloc_mode, JFFS2_SUMMARY_INODE_SIZE);
162 down(&f->sem); 162 down(&f->sem);
163 } 163 }
164 164
165 if (!ret) { 165 if (!ret) {
166 flash_ofs = write_ofs(c);
166 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); 167 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
167 168
168 jffs2_dbg_acct_sanity_check(c,jeb); 169 jffs2_dbg_acct_sanity_check(c,jeb);
@@ -189,13 +190,7 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
189 } else { 190 } else {
190 raw->flash_offset |= REF_NORMAL; 191 raw->flash_offset |= REF_NORMAL;
191 } 192 }
192 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(*ri)+datalen)); 193 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(*ri)+datalen), f->inocache);
193
194 /* Link into per-inode list */
195 spin_lock(&c->erase_completion_lock);
196 raw->next_in_ino = f->inocache->nodes;
197 f->inocache->nodes = raw;
198 spin_unlock(&c->erase_completion_lock);
199 194
200 D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x(%d) with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n", 195 D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x(%d) with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n",
201 flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize), 196 flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize),
@@ -209,12 +204,15 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
209 return fn; 204 return fn;
210} 205}
211 206
212struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_raw_dirent *rd, const unsigned char *name, uint32_t namelen, uint32_t flash_ofs, int alloc_mode) 207struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
208 struct jffs2_raw_dirent *rd, const unsigned char *name,
209 uint32_t namelen, int alloc_mode)
213{ 210{
214 struct jffs2_raw_node_ref *raw; 211 struct jffs2_raw_node_ref *raw;
215 struct jffs2_full_dirent *fd; 212 struct jffs2_full_dirent *fd;
216 size_t retlen; 213 size_t retlen;
217 struct kvec vecs[2]; 214 struct kvec vecs[2];
215 uint32_t flash_ofs = write_ofs(c);
218 int retried = 0; 216 int retried = 0;
219 int ret; 217 int ret;
220 218
@@ -275,9 +273,8 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
275 sizeof(*rd)+namelen, flash_ofs, ret, retlen); 273 sizeof(*rd)+namelen, flash_ofs, ret, retlen);
276 /* Mark the space as dirtied */ 274 /* Mark the space as dirtied */
277 if (retlen) { 275 if (retlen) {
278 raw->next_in_ino = NULL;
279 raw->flash_offset |= REF_OBSOLETE; 276 raw->flash_offset |= REF_OBSOLETE;
280 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(*rd)+namelen)); 277 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(*rd)+namelen), NULL);
281 jffs2_mark_node_obsolete(c, raw); 278 jffs2_mark_node_obsolete(c, raw);
282 } else { 279 } else {
283 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset); 280 printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset);
@@ -296,19 +293,20 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
296 jffs2_dbg_acct_paranoia_check(c, jeb); 293 jffs2_dbg_acct_paranoia_check(c, jeb);
297 294
298 if (alloc_mode == ALLOC_GC) { 295 if (alloc_mode == ALLOC_GC) {
299 ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs, 296 ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &dummy,
300 &dummy, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 297 JFFS2_SUMMARY_DIRENT_SIZE(namelen));
301 } else { 298 } else {
302 /* Locking pain */ 299 /* Locking pain */
303 up(&f->sem); 300 up(&f->sem);
304 jffs2_complete_reservation(c); 301 jffs2_complete_reservation(c);
305 302
306 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs, 303 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &dummy,
307 &dummy, alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 304 alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
308 down(&f->sem); 305 down(&f->sem);
309 } 306 }
310 307
311 if (!ret) { 308 if (!ret) {
309 flash_ofs = write_ofs(c);
312 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs)); 310 D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
313 jffs2_dbg_acct_sanity_check(c,jeb); 311 jffs2_dbg_acct_sanity_check(c,jeb);
314 jffs2_dbg_acct_paranoia_check(c, jeb); 312 jffs2_dbg_acct_paranoia_check(c, jeb);
@@ -323,12 +321,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
323 } 321 }
324 /* Mark the space used */ 322 /* Mark the space used */
325 raw->flash_offset |= REF_PRISTINE; 323 raw->flash_offset |= REF_PRISTINE;
326 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(*rd)+namelen)); 324 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(*rd)+namelen), f->inocache);
327
328 spin_lock(&c->erase_completion_lock);
329 raw->next_in_ino = f->inocache->nodes;
330 f->inocache->nodes = raw;
331 spin_unlock(&c->erase_completion_lock);
332 325
333 if (retried) { 326 if (retried) {
334 jffs2_dbg_acct_sanity_check(c,NULL); 327 jffs2_dbg_acct_sanity_check(c,NULL);
@@ -354,14 +347,14 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
354 struct jffs2_full_dnode *fn; 347 struct jffs2_full_dnode *fn;
355 unsigned char *comprbuf = NULL; 348 unsigned char *comprbuf = NULL;
356 uint16_t comprtype = JFFS2_COMPR_NONE; 349 uint16_t comprtype = JFFS2_COMPR_NONE;
357 uint32_t phys_ofs, alloclen; 350 uint32_t alloclen;
358 uint32_t datalen, cdatalen; 351 uint32_t datalen, cdatalen;
359 int retried = 0; 352 int retried = 0;
360 353
361 retry: 354 retry:
362 D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset)); 355 D2(printk(KERN_DEBUG "jffs2_commit_write() loop: 0x%x to write to 0x%x\n", writelen, offset));
363 356
364 ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN, &phys_ofs, 357 ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN,
365 &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 358 &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
366 if (ret) { 359 if (ret) {
367 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret)); 360 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret));
@@ -389,7 +382,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
389 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 382 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
390 ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); 383 ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
391 384
392 fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, phys_ofs, ALLOC_NORETRY); 385 fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, ALLOC_NORETRY);
393 386
394 jffs2_free_comprbuf(comprbuf, buf); 387 jffs2_free_comprbuf(comprbuf, buf);
395 388
@@ -443,13 +436,13 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
443 struct jffs2_raw_dirent *rd; 436 struct jffs2_raw_dirent *rd;
444 struct jffs2_full_dnode *fn; 437 struct jffs2_full_dnode *fn;
445 struct jffs2_full_dirent *fd; 438 struct jffs2_full_dirent *fd;
446 uint32_t alloclen, phys_ofs; 439 uint32_t alloclen;
447 int ret; 440 int ret;
448 441
449 /* Try to reserve enough space for both node and dirent. 442 /* Try to reserve enough space for both node and dirent.
450 * Just the node will do for now, though 443 * Just the node will do for now, though
451 */ 444 */
452 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL, 445 ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
453 JFFS2_SUMMARY_INODE_SIZE); 446 JFFS2_SUMMARY_INODE_SIZE);
454 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen)); 447 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen));
455 if (ret) { 448 if (ret) {
@@ -460,7 +453,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
460 ri->data_crc = cpu_to_je32(0); 453 ri->data_crc = cpu_to_je32(0);
461 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 454 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
462 455
463 fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, ALLOC_NORMAL); 456 fn = jffs2_write_dnode(c, f, ri, NULL, 0, ALLOC_NORMAL);
464 457
465 D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n", 458 D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n",
466 jemode_to_cpu(ri->mode))); 459 jemode_to_cpu(ri->mode)));
@@ -479,7 +472,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
479 472
480 up(&f->sem); 473 up(&f->sem);
481 jffs2_complete_reservation(c); 474 jffs2_complete_reservation(c);
482 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 475 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
483 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 476 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
484 477
485 if (ret) { 478 if (ret) {
@@ -511,7 +504,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
511 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 504 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
512 rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); 505 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
513 506
514 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL); 507 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL);
515 508
516 jffs2_free_raw_dirent(rd); 509 jffs2_free_raw_dirent(rd);
517 510
@@ -540,7 +533,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
540{ 533{
541 struct jffs2_raw_dirent *rd; 534 struct jffs2_raw_dirent *rd;
542 struct jffs2_full_dirent *fd; 535 struct jffs2_full_dirent *fd;
543 uint32_t alloclen, phys_ofs; 536 uint32_t alloclen;
544 int ret; 537 int ret;
545 538
546 if (1 /* alternative branch needs testing */ || 539 if (1 /* alternative branch needs testing */ ||
@@ -551,7 +544,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
551 if (!rd) 544 if (!rd)
552 return -ENOMEM; 545 return -ENOMEM;
553 546
554 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 547 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
555 ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 548 ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
556 if (ret) { 549 if (ret) {
557 jffs2_free_raw_dirent(rd); 550 jffs2_free_raw_dirent(rd);
@@ -575,7 +568,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
575 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 568 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
576 rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); 569 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
577 570
578 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_DELETION); 571 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_DELETION);
579 572
580 jffs2_free_raw_dirent(rd); 573 jffs2_free_raw_dirent(rd);
581 574
@@ -654,14 +647,14 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
654{ 647{
655 struct jffs2_raw_dirent *rd; 648 struct jffs2_raw_dirent *rd;
656 struct jffs2_full_dirent *fd; 649 struct jffs2_full_dirent *fd;
657 uint32_t alloclen, phys_ofs; 650 uint32_t alloclen;
658 int ret; 651 int ret;
659 652
660 rd = jffs2_alloc_raw_dirent(); 653 rd = jffs2_alloc_raw_dirent();
661 if (!rd) 654 if (!rd)
662 return -ENOMEM; 655 return -ENOMEM;
663 656
664 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 657 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
665 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 658 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
666 if (ret) { 659 if (ret) {
667 jffs2_free_raw_dirent(rd); 660 jffs2_free_raw_dirent(rd);
@@ -687,7 +680,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
687 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 680 rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
688 rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); 681 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
689 682
690 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, ALLOC_NORMAL); 683 fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL);
691 684
692 jffs2_free_raw_dirent(rd); 685 jffs2_free_raw_dirent(rd);
693 686
diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index e16f8460ff04..008f91b1c171 100644
--- a/fs/jffs2/xattr.c
+++ b/fs/jffs2/xattr.c
@@ -49,9 +49,9 @@
49 * is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum(). 49 * is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum().
50 * If xd need to call do_verify_xattr_datum() at first, it's called before calling 50 * If xd need to call do_verify_xattr_datum() at first, it's called before calling
51 * do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum(). 51 * do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum().
52 * save_xattr_datum(c, xd, phys_ofs) 52 * save_xattr_datum(c, xd)
53 * is used to write xdatum to medium. xd->version will be incremented. 53 * is used to write xdatum to medium. xd->version will be incremented.
54 * create_xattr_datum(c, xprefix, xname, xvalue, xsize, phys_ofs) 54 * create_xattr_datum(c, xprefix, xname, xvalue, xsize)
55 * is used to create new xdatum and write to medium. 55 * is used to create new xdatum and write to medium.
56 * -------------------------------------------------- */ 56 * -------------------------------------------------- */
57 57
@@ -301,7 +301,7 @@ static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
301 return rc; 301 return rc;
302} 302}
303 303
304static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd, uint32_t phys_ofs) 304static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
305{ 305{
306 /* must be called under down_write(xattr_sem) */ 306 /* must be called under down_write(xattr_sem) */
307 struct jffs2_raw_xattr rx; 307 struct jffs2_raw_xattr rx;
@@ -309,6 +309,7 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
309 struct kvec vecs[2]; 309 struct kvec vecs[2];
310 uint32_t length; 310 uint32_t length;
311 int rc, totlen; 311 int rc, totlen;
312 uint32_t phys_ofs = write_ofs(c);
312 313
313 BUG_ON(!xd->xname); 314 BUG_ON(!xd->xname);
314 315
@@ -322,7 +323,6 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
322 if (!raw) 323 if (!raw)
323 return -ENOMEM; 324 return -ENOMEM;
324 raw->flash_offset = phys_ofs; 325 raw->flash_offset = phys_ofs;
325 raw->next_in_ino = (void *)xd;
326 326
327 /* Setup raw-xattr */ 327 /* Setup raw-xattr */
328 rx.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 328 rx.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -345,8 +345,7 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
345 rc = rc ? rc : -EIO; 345 rc = rc ? rc : -EIO;
346 if (length) { 346 if (length) {
347 raw->flash_offset |= REF_OBSOLETE; 347 raw->flash_offset |= REF_OBSOLETE;
348 raw->next_in_ino = NULL; 348 jffs2_add_physical_node_ref(c, raw, PAD(totlen), NULL);
349 jffs2_add_physical_node_ref(c, raw, PAD(totlen));
350 jffs2_mark_node_obsolete(c, raw); 349 jffs2_mark_node_obsolete(c, raw);
351 } else { 350 } else {
352 jffs2_free_raw_node_ref(raw); 351 jffs2_free_raw_node_ref(raw);
@@ -356,7 +355,9 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
356 355
357 /* success */ 356 /* success */
358 raw->flash_offset |= REF_PRISTINE; 357 raw->flash_offset |= REF_PRISTINE;
359 jffs2_add_physical_node_ref(c, raw, PAD(totlen)); 358 jffs2_add_physical_node_ref(c, raw, PAD(totlen), NULL);
359 /* FIXME */ raw->next_in_ino = (void *)xd;
360
360 if (xd->node) 361 if (xd->node)
361 delete_xattr_datum_node(c, xd); 362 delete_xattr_datum_node(c, xd);
362 xd->node = raw; 363 xd->node = raw;
@@ -369,8 +370,7 @@ static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
369 370
370static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c, 371static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
371 int xprefix, const char *xname, 372 int xprefix, const char *xname,
372 const char *xvalue, int xsize, 373 const char *xvalue, int xsize)
373 uint32_t phys_ofs)
374{ 374{
375 /* must be called under down_write(xattr_sem) */ 375 /* must be called under down_write(xattr_sem) */
376 struct jffs2_xattr_datum *xd; 376 struct jffs2_xattr_datum *xd;
@@ -419,7 +419,7 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
419 xd->value_len = xsize; 419 xd->value_len = xsize;
420 xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len); 420 xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len);
421 421
422 rc = save_xattr_datum(c, xd, phys_ofs); 422 rc = save_xattr_datum(c, xd);
423 if (rc) { 423 if (rc) {
424 kfree(xd->xname); 424 kfree(xd->xname);
425 jffs2_free_xattr_datum(xd); 425 jffs2_free_xattr_datum(xd);
@@ -446,9 +446,9 @@ static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
446 * delete_xattr_ref(c, ref) 446 * delete_xattr_ref(c, ref)
447 * is used to delete jffs2_xattr_ref object. If the reference counter of xdatum 447 * is used to delete jffs2_xattr_ref object. If the reference counter of xdatum
448 * is refered by this xref become 0, delete_xattr_datum() is called later. 448 * is refered by this xref become 0, delete_xattr_datum() is called later.
449 * save_xattr_ref(c, ref, phys_ofs) 449 * save_xattr_ref(c, ref)
450 * is used to write xref to medium. 450 * is used to write xref to medium.
451 * create_xattr_ref(c, ic, xd, phys_ofs) 451 * create_xattr_ref(c, ic, xd)
452 * is used to create a new xref and write to medium. 452 * is used to create a new xref and write to medium.
453 * jffs2_xattr_delete_inode(c, ic) 453 * jffs2_xattr_delete_inode(c, ic)
454 * is called to remove xrefs related to obsolete inode when inode is unlinked. 454 * is called to remove xrefs related to obsolete inode when inode is unlinked.
@@ -554,19 +554,19 @@ static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *re
554 jffs2_free_xattr_ref(ref); 554 jffs2_free_xattr_ref(ref);
555} 555}
556 556
557static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref, uint32_t phys_ofs) 557static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
558{ 558{
559 /* must be called under down_write(xattr_sem) */ 559 /* must be called under down_write(xattr_sem) */
560 struct jffs2_raw_node_ref *raw; 560 struct jffs2_raw_node_ref *raw;
561 struct jffs2_raw_xref rr; 561 struct jffs2_raw_xref rr;
562 uint32_t length; 562 uint32_t length;
563 uint32_t phys_ofs = write_ofs(c);
563 int ret; 564 int ret;
564 565
565 raw = jffs2_alloc_raw_node_ref(); 566 raw = jffs2_alloc_raw_node_ref();
566 if (!raw) 567 if (!raw)
567 return -ENOMEM; 568 return -ENOMEM;
568 raw->flash_offset = phys_ofs; 569 raw->flash_offset = phys_ofs;
569 raw->next_in_ino = (void *)ref;
570 570
571 rr.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 571 rr.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
572 rr.nodetype = cpu_to_je16(JFFS2_NODETYPE_XREF); 572 rr.nodetype = cpu_to_je16(JFFS2_NODETYPE_XREF);
@@ -584,8 +584,7 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
584 ret = ret ? ret : -EIO; 584 ret = ret ? ret : -EIO;
585 if (length) { 585 if (length) {
586 raw->flash_offset |= REF_OBSOLETE; 586 raw->flash_offset |= REF_OBSOLETE;
587 raw->next_in_ino = NULL; 587 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(rr)), NULL);
588 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(rr)));
589 jffs2_mark_node_obsolete(c, raw); 588 jffs2_mark_node_obsolete(c, raw);
590 } else { 589 } else {
591 jffs2_free_raw_node_ref(raw); 590 jffs2_free_raw_node_ref(raw);
@@ -594,7 +593,8 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
594 } 593 }
595 raw->flash_offset |= REF_PRISTINE; 594 raw->flash_offset |= REF_PRISTINE;
596 595
597 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(rr))); 596 jffs2_add_physical_node_ref(c, raw, PAD(sizeof(rr)), NULL);
597 /* FIXME */ raw->next_in_ino = (void *)ref;
598 if (ref->node) 598 if (ref->node)
599 delete_xattr_ref_node(c, ref); 599 delete_xattr_ref_node(c, ref);
600 ref->node = raw; 600 ref->node = raw;
@@ -605,7 +605,7 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
605} 605}
606 606
607static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, 607static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic,
608 struct jffs2_xattr_datum *xd, uint32_t phys_ofs) 608 struct jffs2_xattr_datum *xd)
609{ 609{
610 /* must be called under down_write(xattr_sem) */ 610 /* must be called under down_write(xattr_sem) */
611 struct jffs2_xattr_ref *ref; 611 struct jffs2_xattr_ref *ref;
@@ -617,7 +617,7 @@ static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct
617 ref->ic = ic; 617 ref->ic = ic;
618 ref->xd = xd; 618 ref->xd = xd;
619 619
620 ret = save_xattr_ref(c, ref, phys_ofs); 620 ret = save_xattr_ref(c, ref);
621 if (ret) { 621 if (ret) {
622 jffs2_free_xattr_ref(ref); 622 jffs2_free_xattr_ref(ref);
623 return ERR_PTR(ret); 623 return ERR_PTR(ret);
@@ -1063,7 +1063,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1063 struct jffs2_inode_cache *ic = f->inocache; 1063 struct jffs2_inode_cache *ic = f->inocache;
1064 struct jffs2_xattr_datum *xd; 1064 struct jffs2_xattr_datum *xd;
1065 struct jffs2_xattr_ref *ref, *newref, **pref; 1065 struct jffs2_xattr_ref *ref, *newref, **pref;
1066 uint32_t phys_ofs, length, request; 1066 uint32_t length, request;
1067 int rc; 1067 int rc;
1068 1068
1069 rc = check_xattr_ref_inode(c, ic); 1069 rc = check_xattr_ref_inode(c, ic);
@@ -1071,7 +1071,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1071 return rc; 1071 return rc;
1072 1072
1073 request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size); 1073 request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size);
1074 rc = jffs2_reserve_space(c, request, &phys_ofs, &length, 1074 rc = jffs2_reserve_space(c, request, &length,
1075 ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE); 1075 ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE);
1076 if (rc) { 1076 if (rc) {
1077 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); 1077 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
@@ -1118,7 +1118,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1118 goto out; 1118 goto out;
1119 } 1119 }
1120 found: 1120 found:
1121 xd = create_xattr_datum(c, xprefix, xname, buffer, size, phys_ofs); 1121 xd = create_xattr_datum(c, xprefix, xname, buffer, size);
1122 if (IS_ERR(xd)) { 1122 if (IS_ERR(xd)) {
1123 rc = PTR_ERR(xd); 1123 rc = PTR_ERR(xd);
1124 goto out; 1124 goto out;
@@ -1128,7 +1128,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1128 1128
1129 /* create xattr_ref */ 1129 /* create xattr_ref */
1130 request = PAD(sizeof(struct jffs2_raw_xref)); 1130 request = PAD(sizeof(struct jffs2_raw_xref));
1131 rc = jffs2_reserve_space(c, request, &phys_ofs, &length, 1131 rc = jffs2_reserve_space(c, request, &length,
1132 ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE); 1132 ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE);
1133 if (rc) { 1133 if (rc) {
1134 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); 1134 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
@@ -1142,7 +1142,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1142 down_write(&c->xattr_sem); 1142 down_write(&c->xattr_sem);
1143 if (ref) 1143 if (ref)
1144 *pref = ref->next; 1144 *pref = ref->next;
1145 newref = create_xattr_ref(c, ic, xd, phys_ofs); 1145 newref = create_xattr_ref(c, ic, xd);
1146 if (IS_ERR(newref)) { 1146 if (IS_ERR(newref)) {
1147 if (ref) { 1147 if (ref) {
1148 ref->next = ic->xref; 1148 ref->next = ic->xref;
@@ -1171,7 +1171,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1171 * -------------------------------------------------- */ 1171 * -------------------------------------------------- */
1172int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) 1172int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
1173{ 1173{
1174 uint32_t phys_ofs, totlen, length, old_ofs; 1174 uint32_t totlen, length, old_ofs;
1175 int rc = -EINVAL; 1175 int rc = -EINVAL;
1176 1176
1177 down_write(&c->xattr_sem); 1177 down_write(&c->xattr_sem);
@@ -1191,13 +1191,13 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
1191 } else if (unlikely(rc < 0)) 1191 } else if (unlikely(rc < 0))
1192 goto out; 1192 goto out;
1193 } 1193 }
1194 rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XATTR_SIZE); 1194 rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE);
1195 if (rc || length < totlen) { 1195 if (rc || length < totlen) {
1196 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen); 1196 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen);
1197 rc = rc ? rc : -EBADFD; 1197 rc = rc ? rc : -EBADFD;
1198 goto out; 1198 goto out;
1199 } 1199 }
1200 rc = save_xattr_datum(c, xd, phys_ofs); 1200 rc = save_xattr_datum(c, xd);
1201 if (!rc) 1201 if (!rc)
1202 dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n", 1202 dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n",
1203 xd->xid, xd->version, old_ofs, ref_offset(xd->node)); 1203 xd->xid, xd->version, old_ofs, ref_offset(xd->node));
@@ -1209,7 +1209,7 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
1209 1209
1210int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) 1210int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
1211{ 1211{
1212 uint32_t phys_ofs, totlen, length, old_ofs; 1212 uint32_t totlen, length, old_ofs;
1213 int rc = -EINVAL; 1213 int rc = -EINVAL;
1214 1214
1215 down_write(&c->xattr_sem); 1215 down_write(&c->xattr_sem);
@@ -1220,14 +1220,14 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
1220 if (totlen != sizeof(struct jffs2_raw_xref)) 1220 if (totlen != sizeof(struct jffs2_raw_xref))
1221 goto out; 1221 goto out;
1222 1222
1223 rc = jffs2_reserve_space_gc(c, totlen, &phys_ofs, &length, JFFS2_SUMMARY_XREF_SIZE); 1223 rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE);
1224 if (rc || length < totlen) { 1224 if (rc || length < totlen) {
1225 JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n", 1225 JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n",
1226 __FUNCTION__, rc, totlen); 1226 __FUNCTION__, rc, totlen);
1227 rc = rc ? rc : -EBADFD; 1227 rc = rc ? rc : -EBADFD;
1228 goto out; 1228 goto out;
1229 } 1229 }
1230 rc = save_xattr_ref(c, ref, phys_ofs); 1230 rc = save_xattr_ref(c, ref);
1231 if (!rc) 1231 if (!rc)
1232 dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n", 1232 dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
1233 ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node)); 1233 ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
diff --git a/fs/jffs2/xattr.h b/fs/jffs2/xattr.h
index e2aa2394ab64..2c199856c582 100644
--- a/fs/jffs2/xattr.h
+++ b/fs/jffs2/xattr.h
@@ -20,11 +20,11 @@
20struct jffs2_xattr_datum 20struct jffs2_xattr_datum
21{ 21{
22 void *always_null; 22 void *always_null;
23 u8 class;
24 u8 flags;
25 u16 xprefix; /* see JFFS2_XATTR_PREFIX_* */
26
27 struct jffs2_raw_node_ref *node; 23 struct jffs2_raw_node_ref *node;
24 uint8_t class;
25 uint8_t flags;
26 uint16_t xprefix; /* see JFFS2_XATTR_PREFIX_* */
27
28 struct list_head xindex; /* chained from c->xattrindex[n] */ 28 struct list_head xindex; /* chained from c->xattrindex[n] */
29 uint32_t refcnt; /* # of xattr_ref refers this */ 29 uint32_t refcnt; /* # of xattr_ref refers this */
30 uint32_t xid; 30 uint32_t xid;
@@ -42,11 +42,11 @@ struct jffs2_inode_cache;
42struct jffs2_xattr_ref 42struct jffs2_xattr_ref
43{ 43{
44 void *always_null; 44 void *always_null;
45 u8 class; 45 struct jffs2_raw_node_ref *node;
46 u8 flags; /* Currently unused */ 46 uint8_t class;
47 uint8_t flags; /* Currently unused */
47 u16 unused; 48 u16 unused;
48 49
49 struct jffs2_raw_node_ref *node;
50 union { 50 union {
51 struct jffs2_inode_cache *ic; /* reference to jffs2_inode_cache */ 51 struct jffs2_inode_cache *ic; /* reference to jffs2_inode_cache */
52 uint32_t ino; /* only used in scanning/building */ 52 uint32_t ino; /* only used in scanning/building */