kernel: update kernel 4.1 to version 4.1.23
[openwrt.git] / target / linux / generic / patches-4.1 / 111-jffs2-add-RENAME_EXCHANGE-support.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Date: Sat, 25 Apr 2015 12:41:32 +0200
3 Subject: [PATCH] jffs2: add RENAME_EXCHANGE support
4
5 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
6 ---
7
8 --- a/fs/jffs2/dir.c
9 +++ b/fs/jffs2/dir.c
10 @@ -784,7 +784,7 @@ static int jffs2_rename (struct inode *o
11         uint8_t type;
12         uint32_t now;
13  
14 -       if (flags & ~RENAME_WHITEOUT)
15 +       if (flags & ~(RENAME_WHITEOUT | RENAME_EXCHANGE))
16                 return -EINVAL;
17  
18         /* The VFS will check for us and prevent trying to rename a
19 @@ -792,7 +792,7 @@ static int jffs2_rename (struct inode *o
20          * the VFS can't check whether the victim is empty. The filesystem
21          * needs to do that for itself.
22          */
23 -       if (d_really_is_positive(new_dentry)) {
24 +       if (d_really_is_positive(new_dentry) && !(flags & RENAME_EXCHANGE)) {
25                 victim_f = JFFS2_INODE_INFO(d_inode(new_dentry));
26                 if (d_is_dir(new_dentry)) {
27                         struct jffs2_full_dirent *fd;
28 @@ -827,7 +827,7 @@ static int jffs2_rename (struct inode *o
29         if (ret)
30                 return ret;
31  
32 -       if (victim_f) {
33 +       if (victim_f && !(flags & RENAME_EXCHANGE)) {
34                 /* There was a victim. Kill it off nicely */
35                 if (d_is_dir(new_dentry))
36                         clear_nlink(d_inode(new_dentry));
37 @@ -853,6 +853,12 @@ static int jffs2_rename (struct inode *o
38         if (flags & RENAME_WHITEOUT)
39                 /* Replace with whiteout */
40                 ret = jffs2_whiteout(old_dir_i, old_dentry);
41 +       else if (flags & RENAME_EXCHANGE)
42 +               /* Replace the original */
43 +               ret = jffs2_do_link(c, JFFS2_INODE_INFO(old_dir_i),
44 +                                   d_inode(new_dentry)->i_ino, type,
45 +                                   old_dentry->d_name.name, old_dentry->d_name.len,
46 +                                   now);
47         else
48                 /* Unlink the original */
49                 ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
50 @@ -884,7 +890,7 @@ static int jffs2_rename (struct inode *o
51                 return ret;
52         }
53  
54 -       if (d_is_dir(old_dentry))
55 +       if (d_is_dir(old_dentry) && !(flags & RENAME_EXCHANGE))
56                 drop_nlink(old_dir_i);
57  
58         new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = ITIME(now);