From: Roman Zippel <zippel@linux-m68k.org>

Write back the information for a dirty resource inode directly and not via the
main inode, as at the time the latter is written the former might already be
gone.

Signed-off-by: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/fs/hfs/inode.c     |   25 ++++++++++++++-----------
 25-akpm/fs/hfsplus/inode.c |   24 ++++++++++++++----------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff -puN fs/hfs/inode.c~hfs-write-back-resource-info-directly fs/hfs/inode.c
--- 25/fs/hfs/inode.c~hfs-write-back-resource-info-directly	Wed Oct 20 16:41:24 2004
+++ 25-akpm/fs/hfs/inode.c	Wed Oct 20 16:41:25 2004
@@ -386,6 +386,7 @@ void hfs_inode_write_fork(struct inode *
 
 int hfs_write_inode(struct inode *inode, int unused)
 {
+	struct inode *main_inode = inode;
 	struct hfs_find_data fd;
 	hfs_cat_rec rec;
 
@@ -408,24 +409,22 @@ int hfs_write_inode(struct inode *inode,
 		}
 	}
 
-	if (HFS_IS_RSRC(inode)) {
-		mark_inode_dirty(HFS_I(inode)->rsrc_inode);
-		return 0;
-	}
+	if (HFS_IS_RSRC(inode))
+		main_inode = HFS_I(inode)->rsrc_inode;
 
-	if (!inode->i_nlink)
+	if (!main_inode->i_nlink)
 		return 0;
 
-	if (hfs_find_init(HFS_SB(inode->i_sb)->cat_tree, &fd))
+	if (hfs_find_init(HFS_SB(main_inode->i_sb)->cat_tree, &fd))
 		/* panic? */
 		return -EIO;
 
-	fd.search_key->cat = HFS_I(inode)->cat_key;
+	fd.search_key->cat = HFS_I(main_inode)->cat_key;
 	if (hfs_brec_find(&fd))
 		/* panic? */
 		goto out;
 
-	if (S_ISDIR(inode->i_mode)) {
+	if (S_ISDIR(main_inode->i_mode)) {
 		if (fd.entrylength < sizeof(struct hfs_cat_dir))
 			/* panic? */;
 		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
@@ -439,6 +438,13 @@ int hfs_write_inode(struct inode *inode,
 
 		hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
 			    sizeof(struct hfs_cat_dir));
+	} else if (HFS_IS_RSRC(inode)) {
+		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
+			       sizeof(struct hfs_cat_file));
+		hfs_inode_write_fork(inode, rec.file.RExtRec,
+				     &rec.file.RLgLen, &rec.file.RPyLen);
+		hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
+				sizeof(struct hfs_cat_file));
 	} else {
 		if (fd.entrylength < sizeof(struct hfs_cat_file))
 			/* panic? */;
@@ -453,9 +459,6 @@ int hfs_write_inode(struct inode *inode,
 		else
 			rec.file.Flags |= HFS_FIL_LOCK;
 		hfs_inode_write_fork(inode, rec.file.ExtRec, &rec.file.LgLen, &rec.file.PyLen);
-		if (HFS_I(inode)->rsrc_inode)
-			hfs_inode_write_fork(HFS_I(inode)->rsrc_inode, rec.file.RExtRec,
-					     &rec.file.RLgLen, &rec.file.RPyLen);
 		rec.file.MdDat = hfs_u_to_mtime(inode->i_mtime);
 
 		hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
diff -puN fs/hfsplus/inode.c~hfs-write-back-resource-info-directly fs/hfsplus/inode.c
--- 25/fs/hfsplus/inode.c~hfs-write-back-resource-info-directly	Wed Oct 20 16:41:24 2004
+++ 25-akpm/fs/hfsplus/inode.c	Wed Oct 20 16:41:25 2004
@@ -489,26 +489,25 @@ int hfsplus_cat_read_inode(struct inode 
 
 int hfsplus_cat_write_inode(struct inode *inode)
 {
+	struct inode *main_inode = inode;
 	struct hfs_find_data fd;
 	hfsplus_cat_entry entry;
 
-	if (HFSPLUS_IS_RSRC(inode)) {
-		mark_inode_dirty(HFSPLUS_I(inode).rsrc_inode);
-		return 0;
-	}
+	if (HFSPLUS_IS_RSRC(inode))
+		main_inode = HFSPLUS_I(inode).rsrc_inode;
 
-	if (!inode->i_nlink)
+	if (!main_inode->i_nlink)
 		return 0;
 
-	if (hfs_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd))
+	if (hfs_find_init(HFSPLUS_SB(main_inode->i_sb).cat_tree, &fd))
 		/* panic? */
 		return -EIO;
 
-	if (hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd))
+	if (hfsplus_find_cat(main_inode->i_sb, main_inode->i_ino, &fd))
 		/* panic? */
 		goto out;
 
-	if (S_ISDIR(inode->i_mode)) {
+	if (S_ISDIR(main_inode->i_mode)) {
 		struct hfsplus_cat_folder *folder = &entry.folder;
 
 		if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
@@ -523,6 +522,13 @@ int hfsplus_cat_write_inode(struct inode
 		folder->valence = cpu_to_be32(inode->i_size - 2);
 		hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
 					 sizeof(struct hfsplus_cat_folder));
+	} else if (HFSPLUS_IS_RSRC(inode)) {
+		struct hfsplus_cat_file *file = &entry.file;
+		hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
+			       sizeof(struct hfsplus_cat_file));
+		hfsplus_inode_write_fork(inode, &file->rsrc_fork);
+		hfs_bnode_write(fd.bnode, &entry, fd.entryoffset,
+				sizeof(struct hfsplus_cat_file));
 	} else {
 		struct hfsplus_cat_file *file = &entry.file;
 
@@ -531,8 +537,6 @@ int hfsplus_cat_write_inode(struct inode
 		hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
 					sizeof(struct hfsplus_cat_file));
 		hfsplus_inode_write_fork(inode, &file->data_fork);
-		if (HFSPLUS_I(inode).rsrc_inode)
-			hfsplus_inode_write_fork(HFSPLUS_I(inode).rsrc_inode, &file->rsrc_fork);
 		if (S_ISREG(inode->i_mode))
 			HFSPLUS_I(inode).dev = inode->i_nlink;
 		if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
_