kernel: Fix the incorrect i_nlink count after jffs2's RENAME_EXCHANGE operations.
authorJing Qiu <aqiu0720@gmail.com>
Tue, 14 Mar 2017 07:32:08 +0000 (15:32 +0800)
committerFelix Fietkau <nbd@nbd.name>
Wed, 5 Apr 2017 07:57:41 +0000 (09:57 +0200)
commit638ca50f3b1d66fb165891552ed8cde31aa2f194
tree0480bc17e29874bdf8e53349dc8f7a3658d1a1cc
parent47bf110cbbfbb425d7538c566332d2058fb45248
kernel: Fix the incorrect i_nlink count after jffs2's RENAME_EXCHANGE operations.

The problem is caused by the incorrect handling of the parent inode's
i_nlink count for the dentry to be RENAME_EXCHANGED. There are 3 cases
to consider. Assume we want to RENAME_EXCHANGE struct dentry *a and
struct dentry *b, and inode_a is pointed to by dentry_a, inode_b is
pointed to by dentry_b:

1. If inode_a is a directory, but inode_b isn't, then we must decrease
   the i_nlink count of old_dir_i, and increase the i_nlink of new_dir_i.
2. If inode_a isn't a directory, but inode_b is a directory, then we
   must increase the i_nlink of old_dir_i, and decrease the i_nlink count
   of new_dir_i.
3. If the types of inode_a and inode_b are the same, we don't change the
   i_nlink for either old_dir_i or new_dir_i.

Signed-off-by: Jing Qiu <aqiu0720@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
target/linux/generic/patches-4.4/111-jffs2-add-RENAME_EXCHANGE-support.patch