aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2006-05-22 19:38:06 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2006-05-22 19:38:06 -0400
commit9fe4854cd1f60273f9a3ece053f4789605f58a5e (patch)
tree277ac17807a1596f78464641500ed35f3d47a32a /fs/jffs2
parent5fa433942ba4e399f7e28764c9db4ade89e91d40 (diff)
[JFFS2] Remove flash offset argument from various functions.
We don't need the upper layers to deal with the physical offset. It's _always_ c->nextblock->offset + c->sector_size - c->nextblock->free_size so we might as well just let the actual write functions deal with that. Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'fs/jffs2')
-rw-r--r--fs/jffs2/dir.c40
-rw-r--r--fs/jffs2/file.c8
-rw-r--r--fs/jffs2/fs.c8
-rw-r--r--fs/jffs2/gc.c34
-rw-r--r--fs/jffs2/nodelist.h23
-rw-r--r--fs/jffs2/nodemgmt.c26
-rw-r--r--fs/jffs2/wbuf.c4
-rw-r--r--fs/jffs2/write.c62
-rw-r--r--fs/jffs2/xattr.c45
9 files changed, 135 insertions, 115 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/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 79f70251a4eb..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
diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c
index 153755bc1d53..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,13 +626,13 @@ 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 nraw->flash_offset |= REF_OBSOLETE; 637 nraw->flash_offset |= REF_OBSOLETE;
638 jffs2_add_physical_node_ref(c, nraw, rawlen, NULL); 638 jffs2_add_physical_node_ref(c, nraw, rawlen, NULL);
@@ -653,7 +653,7 @@ static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
653 jffs2_dbg_acct_sanity_check(c,jeb); 653 jffs2_dbg_acct_sanity_check(c,jeb);
654 jffs2_dbg_acct_paranoia_check(c, jeb); 654 jffs2_dbg_acct_paranoia_check(c, jeb);
655 655
656 ret = jffs2_reserve_space_gc(c, rawlen, &phys_ofs, &dummy, rawlen); 656 ret = jffs2_reserve_space_gc(c, rawlen, &dummy, rawlen);
657 /* this is not the exact summary size of it, 657 /* this is not the exact summary size of it,
658 it is only an upper estimation */ 658 it is only an upper estimation */
659 659
@@ -696,7 +696,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
696 struct jffs2_node_frag *last_frag; 696 struct jffs2_node_frag *last_frag;
697 union jffs2_device_node dev; 697 union jffs2_device_node dev;
698 char *mdata = NULL, mdatalen = 0; 698 char *mdata = NULL, mdatalen = 0;
699 uint32_t alloclen, phys_ofs, ilen; 699 uint32_t alloclen, ilen;
700 int ret; 700 int ret;
701 701
702 if (S_ISBLK(JFFS2_F_I_MODE(f)) || 702 if (S_ISBLK(JFFS2_F_I_MODE(f)) ||
@@ -722,7 +722,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
722 722
723 } 723 }
724 724
725 ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &phys_ofs, &alloclen, 725 ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &alloclen,
726 JFFS2_SUMMARY_INODE_SIZE); 726 JFFS2_SUMMARY_INODE_SIZE);
727 if (ret) { 727 if (ret) {
728 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",
@@ -760,7 +760,7 @@ static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_
760 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));
761 ri.data_crc = cpu_to_je32(crc32(0, mdata, mdatalen)); 761 ri.data_crc = cpu_to_je32(crc32(0, mdata, mdatalen));
762 762
763 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);
764 764
765 if (IS_ERR(new_fn)) { 765 if (IS_ERR(new_fn)) {
766 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));
@@ -781,7 +781,7 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
781{ 781{
782 struct jffs2_full_dirent *new_fd; 782 struct jffs2_full_dirent *new_fd;
783 struct jffs2_raw_dirent rd; 783 struct jffs2_raw_dirent rd;
784 uint32_t alloclen, phys_ofs; 784 uint32_t alloclen;
785 int ret; 785 int ret;
786 786
787 rd.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 787 rd.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
@@ -803,14 +803,14 @@ static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_er
803 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));
804 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));
805 805
806 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,
807 JFFS2_SUMMARY_DIRENT_SIZE(rd.nsize)); 807 JFFS2_SUMMARY_DIRENT_SIZE(rd.nsize));
808 if (ret) { 808 if (ret) {
809 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",
810 sizeof(rd)+rd.nsize, ret); 810 sizeof(rd)+rd.nsize, ret);
811 return ret; 811 return ret;
812 } 812 }
813 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);
814 814
815 if (IS_ERR(new_fd)) { 815 if (IS_ERR(new_fd)) {
816 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));
@@ -938,7 +938,7 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
938 struct jffs2_raw_inode ri; 938 struct jffs2_raw_inode ri;
939 struct jffs2_node_frag *frag; 939 struct jffs2_node_frag *frag;
940 struct jffs2_full_dnode *new_fn; 940 struct jffs2_full_dnode *new_fn;
941 uint32_t alloclen, phys_ofs, ilen; 941 uint32_t alloclen, ilen;
942 int ret; 942 int ret;
943 943
944 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",
@@ -1017,14 +1017,14 @@ static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eras
1017 ri.data_crc = cpu_to_je32(0); 1017 ri.data_crc = cpu_to_je32(0);
1018 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));
1019 1019
1020 ret = jffs2_reserve_space_gc(c, sizeof(ri), &phys_ofs, &alloclen, 1020 ret = jffs2_reserve_space_gc(c, sizeof(ri), &alloclen,
1021 JFFS2_SUMMARY_INODE_SIZE); 1021 JFFS2_SUMMARY_INODE_SIZE);
1022 if (ret) { 1022 if (ret) {
1023 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",
1024 sizeof(ri), ret); 1024 sizeof(ri), ret);
1025 return ret; 1025 return ret;
1026 } 1026 }
1027 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);
1028 1028
1029 if (IS_ERR(new_fn)) { 1029 if (IS_ERR(new_fn)) {
1030 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));
@@ -1086,7 +1086,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1086{ 1086{
1087 struct jffs2_full_dnode *new_fn; 1087 struct jffs2_full_dnode *new_fn;
1088 struct jffs2_raw_inode ri; 1088 struct jffs2_raw_inode ri;
1089 uint32_t alloclen, phys_ofs, offset, orig_end, orig_start; 1089 uint32_t alloclen, offset, orig_end, orig_start;
1090 int ret = 0; 1090 int ret = 0;
1091 unsigned char *comprbuf = NULL, *writebuf; 1091 unsigned char *comprbuf = NULL, *writebuf;
1092 unsigned long pg; 1092 unsigned long pg;
@@ -1243,7 +1243,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1243 uint32_t cdatalen; 1243 uint32_t cdatalen;
1244 uint16_t comprtype = JFFS2_COMPR_NONE; 1244 uint16_t comprtype = JFFS2_COMPR_NONE;
1245 1245
1246 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,
1247 &alloclen, JFFS2_SUMMARY_INODE_SIZE); 1247 &alloclen, JFFS2_SUMMARY_INODE_SIZE);
1248 1248
1249 if (ret) { 1249 if (ret) {
@@ -1280,7 +1280,7 @@ static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_era
1280 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));
1281 ri.data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); 1281 ri.data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
1282 1282
1283 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);
1284 1284
1285 jffs2_free_comprbuf(comprbuf, writebuf); 1285 jffs2_free_comprbuf(comprbuf, writebuf);
1286 1286
diff --git a/fs/jffs2/nodelist.h b/fs/jffs2/nodelist.h
index 1e1c39da6da4..76f1b9419eea 100644
--- a/fs/jffs2/nodelist.h
+++ b/fs/jffs2/nodelist.h
@@ -167,6 +167,8 @@ struct jffs2_inode_cache {
167 167
168#define INOCACHE_HASHSIZE 128 168#define INOCACHE_HASHSIZE 128
169 169
170#define write_ofs(c) ((c)->nextblock->offset + (c)->sector_size - (c)->nextblock->free_size)
171
170/* 172/*
171 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
172 struct inode for this particular ino is instantiated. 174 struct inode for this particular ino is instantiated.
@@ -325,9 +327,9 @@ extern uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c,
325 327
326/* nodemgmt.c */ 328/* nodemgmt.c */
327int jffs2_thread_should_wake(struct jffs2_sb_info *c); 329int jffs2_thread_should_wake(struct jffs2_sb_info *c);
328int 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,
329 uint32_t *len, int prio, uint32_t sumsize); 331 uint32_t *len, int prio, uint32_t sumsize);
330int 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,
331 uint32_t *len, uint32_t sumsize); 333 uint32_t *len, uint32_t sumsize);
332int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, 334int jffs2_add_physical_node_ref(struct jffs2_sb_info *c,
333 struct jffs2_raw_node_ref *new, 335 struct jffs2_raw_node_ref *new,
@@ -339,14 +341,21 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
339/* write.c */ 341/* write.c */
340int 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);
341 343
342struct 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,
343struct 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);
344int 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,
345 struct jffs2_raw_inode *ri, unsigned char *buf, 351 struct jffs2_raw_inode *ri, unsigned char *buf,
346 uint32_t offset, uint32_t writelen, uint32_t *retlen); 352 uint32_t offset, uint32_t writelen, uint32_t *retlen);
347int 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,
348int 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);
349int 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);
350 359
351 360
352/* readinode.c */ 361/* readinode.c */
diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c
index 34a452bdde05..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
diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index 087c2e438a6d..c7e3040240b2 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
diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c
index 319a70f531f8..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);
@@ -147,19 +150,20 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
147 jffs2_dbg_acct_paranoia_check(c, jeb); 150 jffs2_dbg_acct_paranoia_check(c, jeb);
148 151
149 if (alloc_mode == ALLOC_GC) { 152 if (alloc_mode == ALLOC_GC) {
150 ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs, 153 ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &dummy,
151 &dummy, JFFS2_SUMMARY_INODE_SIZE); 154 JFFS2_SUMMARY_INODE_SIZE);
152 } else { 155 } else {
153 /* Locking pain */ 156 /* Locking pain */
154 up(&f->sem); 157 up(&f->sem);
155 jffs2_complete_reservation(c); 158 jffs2_complete_reservation(c);
156 159
157 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs, 160 ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &dummy,
158 &dummy, alloc_mode, JFFS2_SUMMARY_INODE_SIZE); 161 alloc_mode, JFFS2_SUMMARY_INODE_SIZE);
159 down(&f->sem); 162 down(&f->sem);
160 } 163 }
161 164
162 if (!ret) { 165 if (!ret) {
166 flash_ofs = write_ofs(c);
163 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));
164 168
165 jffs2_dbg_acct_sanity_check(c,jeb); 169 jffs2_dbg_acct_sanity_check(c,jeb);
@@ -200,12 +204,15 @@ struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2
200 return fn; 204 return fn;
201} 205}
202 206
203struct 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)
204{ 210{
205 struct jffs2_raw_node_ref *raw; 211 struct jffs2_raw_node_ref *raw;
206 struct jffs2_full_dirent *fd; 212 struct jffs2_full_dirent *fd;
207 size_t retlen; 213 size_t retlen;
208 struct kvec vecs[2]; 214 struct kvec vecs[2];
215 uint32_t flash_ofs = write_ofs(c);
209 int retried = 0; 216 int retried = 0;
210 int ret; 217 int ret;
211 218
@@ -286,19 +293,20 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
286 jffs2_dbg_acct_paranoia_check(c, jeb); 293 jffs2_dbg_acct_paranoia_check(c, jeb);
287 294
288 if (alloc_mode == ALLOC_GC) { 295 if (alloc_mode == ALLOC_GC) {
289 ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &flash_ofs, 296 ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &dummy,
290 &dummy, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 297 JFFS2_SUMMARY_DIRENT_SIZE(namelen));
291 } else { 298 } else {
292 /* Locking pain */ 299 /* Locking pain */
293 up(&f->sem); 300 up(&f->sem);
294 jffs2_complete_reservation(c); 301 jffs2_complete_reservation(c);
295 302
296 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs, 303 ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &dummy,
297 &dummy, alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 304 alloc_mode, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
298 down(&f->sem); 305 down(&f->sem);
299 } 306 }
300 307
301 if (!ret) { 308 if (!ret) {
309 flash_ofs = write_ofs(c);
302 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));
303 jffs2_dbg_acct_sanity_check(c,jeb); 311 jffs2_dbg_acct_sanity_check(c,jeb);
304 jffs2_dbg_acct_paranoia_check(c, jeb); 312 jffs2_dbg_acct_paranoia_check(c, jeb);
@@ -339,14 +347,14 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
339 struct jffs2_full_dnode *fn; 347 struct jffs2_full_dnode *fn;
340 unsigned char *comprbuf = NULL; 348 unsigned char *comprbuf = NULL;
341 uint16_t comprtype = JFFS2_COMPR_NONE; 349 uint16_t comprtype = JFFS2_COMPR_NONE;
342 uint32_t phys_ofs, alloclen; 350 uint32_t alloclen;
343 uint32_t datalen, cdatalen; 351 uint32_t datalen, cdatalen;
344 int retried = 0; 352 int retried = 0;
345 353
346 retry: 354 retry:
347 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));
348 356
349 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,
350 &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE); 358 &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
351 if (ret) { 359 if (ret) {
352 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret)); 360 D1(printk(KERN_DEBUG "jffs2_reserve_space returned %d\n", ret));
@@ -374,7 +382,7 @@ int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
374 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));
375 ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen)); 383 ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
376 384
377 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);
378 386
379 jffs2_free_comprbuf(comprbuf, buf); 387 jffs2_free_comprbuf(comprbuf, buf);
380 388
@@ -428,13 +436,13 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
428 struct jffs2_raw_dirent *rd; 436 struct jffs2_raw_dirent *rd;
429 struct jffs2_full_dnode *fn; 437 struct jffs2_full_dnode *fn;
430 struct jffs2_full_dirent *fd; 438 struct jffs2_full_dirent *fd;
431 uint32_t alloclen, phys_ofs; 439 uint32_t alloclen;
432 int ret; 440 int ret;
433 441
434 /* Try to reserve enough space for both node and dirent. 442 /* Try to reserve enough space for both node and dirent.
435 * Just the node will do for now, though 443 * Just the node will do for now, though
436 */ 444 */
437 ret = jffs2_reserve_space(c, sizeof(*ri), &phys_ofs, &alloclen, ALLOC_NORMAL, 445 ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
438 JFFS2_SUMMARY_INODE_SIZE); 446 JFFS2_SUMMARY_INODE_SIZE);
439 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));
440 if (ret) { 448 if (ret) {
@@ -445,7 +453,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
445 ri->data_crc = cpu_to_je32(0); 453 ri->data_crc = cpu_to_je32(0);
446 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));
447 455
448 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);
449 457
450 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",
451 jemode_to_cpu(ri->mode))); 459 jemode_to_cpu(ri->mode)));
@@ -464,7 +472,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
464 472
465 up(&f->sem); 473 up(&f->sem);
466 jffs2_complete_reservation(c); 474 jffs2_complete_reservation(c);
467 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 475 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
468 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 476 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
469 477
470 if (ret) { 478 if (ret) {
@@ -496,7 +504,7 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
496 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));
497 rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); 505 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
498 506
499 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);
500 508
501 jffs2_free_raw_dirent(rd); 509 jffs2_free_raw_dirent(rd);
502 510
@@ -525,7 +533,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
525{ 533{
526 struct jffs2_raw_dirent *rd; 534 struct jffs2_raw_dirent *rd;
527 struct jffs2_full_dirent *fd; 535 struct jffs2_full_dirent *fd;
528 uint32_t alloclen, phys_ofs; 536 uint32_t alloclen;
529 int ret; 537 int ret;
530 538
531 if (1 /* alternative branch needs testing */ || 539 if (1 /* alternative branch needs testing */ ||
@@ -536,7 +544,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
536 if (!rd) 544 if (!rd)
537 return -ENOMEM; 545 return -ENOMEM;
538 546
539 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 547 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
540 ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 548 ALLOC_DELETION, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
541 if (ret) { 549 if (ret) {
542 jffs2_free_raw_dirent(rd); 550 jffs2_free_raw_dirent(rd);
@@ -560,7 +568,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
560 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));
561 rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); 569 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
562 570
563 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);
564 572
565 jffs2_free_raw_dirent(rd); 573 jffs2_free_raw_dirent(rd);
566 574
@@ -639,14 +647,14 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
639{ 647{
640 struct jffs2_raw_dirent *rd; 648 struct jffs2_raw_dirent *rd;
641 struct jffs2_full_dirent *fd; 649 struct jffs2_full_dirent *fd;
642 uint32_t alloclen, phys_ofs; 650 uint32_t alloclen;
643 int ret; 651 int ret;
644 652
645 rd = jffs2_alloc_raw_dirent(); 653 rd = jffs2_alloc_raw_dirent();
646 if (!rd) 654 if (!rd)
647 return -ENOMEM; 655 return -ENOMEM;
648 656
649 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &phys_ofs, &alloclen, 657 ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
650 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen)); 658 ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
651 if (ret) { 659 if (ret) {
652 jffs2_free_raw_dirent(rd); 660 jffs2_free_raw_dirent(rd);
@@ -672,7 +680,7 @@ int jffs2_do_link (struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint
672 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));
673 rd->name_crc = cpu_to_je32(crc32(0, name, namelen)); 681 rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
674 682
675 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);
676 684
677 jffs2_free_raw_dirent(rd); 685 jffs2_free_raw_dirent(rd);
678 686
diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index 76d166140381..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
@@ -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,12 +554,13 @@ 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();
@@ -604,7 +605,7 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
604} 605}
605 606
606static 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,
607 struct jffs2_xattr_datum *xd, uint32_t phys_ofs) 608 struct jffs2_xattr_datum *xd)
608{ 609{
609 /* must be called under down_write(xattr_sem) */ 610 /* must be called under down_write(xattr_sem) */
610 struct jffs2_xattr_ref *ref; 611 struct jffs2_xattr_ref *ref;
@@ -616,7 +617,7 @@ static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct
616 ref->ic = ic; 617 ref->ic = ic;
617 ref->xd = xd; 618 ref->xd = xd;
618 619
619 ret = save_xattr_ref(c, ref, phys_ofs); 620 ret = save_xattr_ref(c, ref);
620 if (ret) { 621 if (ret) {
621 jffs2_free_xattr_ref(ref); 622 jffs2_free_xattr_ref(ref);
622 return ERR_PTR(ret); 623 return ERR_PTR(ret);
@@ -1062,7 +1063,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1062 struct jffs2_inode_cache *ic = f->inocache; 1063 struct jffs2_inode_cache *ic = f->inocache;
1063 struct jffs2_xattr_datum *xd; 1064 struct jffs2_xattr_datum *xd;
1064 struct jffs2_xattr_ref *ref, *newref, **pref; 1065 struct jffs2_xattr_ref *ref, *newref, **pref;
1065 uint32_t phys_ofs, length, request; 1066 uint32_t length, request;
1066 int rc; 1067 int rc;
1067 1068
1068 rc = check_xattr_ref_inode(c, ic); 1069 rc = check_xattr_ref_inode(c, ic);
@@ -1070,7 +1071,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1070 return rc; 1071 return rc;
1071 1072
1072 request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size); 1073 request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size);
1073 rc = jffs2_reserve_space(c, request, &phys_ofs, &length, 1074 rc = jffs2_reserve_space(c, request, &length,
1074 ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE); 1075 ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE);
1075 if (rc) { 1076 if (rc) {
1076 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); 1077 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
@@ -1117,7 +1118,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1117 goto out; 1118 goto out;
1118 } 1119 }
1119 found: 1120 found:
1120 xd = create_xattr_datum(c, xprefix, xname, buffer, size, phys_ofs); 1121 xd = create_xattr_datum(c, xprefix, xname, buffer, size);
1121 if (IS_ERR(xd)) { 1122 if (IS_ERR(xd)) {
1122 rc = PTR_ERR(xd); 1123 rc = PTR_ERR(xd);
1123 goto out; 1124 goto out;
@@ -1127,7 +1128,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1127 1128
1128 /* create xattr_ref */ 1129 /* create xattr_ref */
1129 request = PAD(sizeof(struct jffs2_raw_xref)); 1130 request = PAD(sizeof(struct jffs2_raw_xref));
1130 rc = jffs2_reserve_space(c, request, &phys_ofs, &length, 1131 rc = jffs2_reserve_space(c, request, &length,
1131 ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE); 1132 ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE);
1132 if (rc) { 1133 if (rc) {
1133 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request); 1134 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
@@ -1141,7 +1142,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1141 down_write(&c->xattr_sem); 1142 down_write(&c->xattr_sem);
1142 if (ref) 1143 if (ref)
1143 *pref = ref->next; 1144 *pref = ref->next;
1144 newref = create_xattr_ref(c, ic, xd, phys_ofs); 1145 newref = create_xattr_ref(c, ic, xd);
1145 if (IS_ERR(newref)) { 1146 if (IS_ERR(newref)) {
1146 if (ref) { 1147 if (ref) {
1147 ref->next = ic->xref; 1148 ref->next = ic->xref;
@@ -1170,7 +1171,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1170 * -------------------------------------------------- */ 1171 * -------------------------------------------------- */
1171int 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)
1172{ 1173{
1173 uint32_t phys_ofs, totlen, length, old_ofs; 1174 uint32_t totlen, length, old_ofs;
1174 int rc = -EINVAL; 1175 int rc = -EINVAL;
1175 1176
1176 down_write(&c->xattr_sem); 1177 down_write(&c->xattr_sem);
@@ -1190,13 +1191,13 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
1190 } else if (unlikely(rc < 0)) 1191 } else if (unlikely(rc < 0))
1191 goto out; 1192 goto out;
1192 } 1193 }
1193 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);
1194 if (rc || length < totlen) { 1195 if (rc || length < totlen) {
1195 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen); 1196 JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, totlen);
1196 rc = rc ? rc : -EBADFD; 1197 rc = rc ? rc : -EBADFD;
1197 goto out; 1198 goto out;
1198 } 1199 }
1199 rc = save_xattr_datum(c, xd, phys_ofs); 1200 rc = save_xattr_datum(c, xd);
1200 if (!rc) 1201 if (!rc)
1201 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",
1202 xd->xid, xd->version, old_ofs, ref_offset(xd->node)); 1203 xd->xid, xd->version, old_ofs, ref_offset(xd->node));
@@ -1208,7 +1209,7 @@ int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xatt
1208 1209
1209int 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)
1210{ 1211{
1211 uint32_t phys_ofs, totlen, length, old_ofs; 1212 uint32_t totlen, length, old_ofs;
1212 int rc = -EINVAL; 1213 int rc = -EINVAL;
1213 1214
1214 down_write(&c->xattr_sem); 1215 down_write(&c->xattr_sem);
@@ -1219,14 +1220,14 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
1219 if (totlen != sizeof(struct jffs2_raw_xref)) 1220 if (totlen != sizeof(struct jffs2_raw_xref))
1220 goto out; 1221 goto out;
1221 1222
1222 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);
1223 if (rc || length < totlen) { 1224 if (rc || length < totlen) {
1224 JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n", 1225 JFFS2_WARNING("%s: jffs2_reserve_space() = %d, request = %u\n",
1225 __FUNCTION__, rc, totlen); 1226 __FUNCTION__, rc, totlen);
1226 rc = rc ? rc : -EBADFD; 1227 rc = rc ? rc : -EBADFD;
1227 goto out; 1228 goto out;
1228 } 1229 }
1229 rc = save_xattr_ref(c, ref, phys_ofs); 1230 rc = save_xattr_ref(c, ref);
1230 if (!rc) 1231 if (!rc)
1231 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",
1232 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));