treewide: fix replace nbd@openwrt.org with nbd@nbd.name
[openwrt.git] / target / linux / generic / patches-3.18 / 111-jffs2-add-RENAME_EXCHANGE-support.patch
1 From: Felix Fietkau <nbd@nbd.name>
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@nbd.name>
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 (new_dentry->d_inode) {
24 +       if (new_dentry->d_inode && !(flags & RENAME_EXCHANGE)) {
25                 victim_f = JFFS2_INODE_INFO(new_dentry->d_inode);
26                 if (S_ISDIR(new_dentry->d_inode->i_mode)) {
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 (S_ISDIR(new_dentry->d_inode->i_mode))
36                         clear_nlink(new_dentry->d_inode);
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 +                                   new_dentry->d_inode->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 @@ -879,7 +885,7 @@ static int jffs2_rename (struct inode *o
51                 return ret;
52         }
53  
54 -       if (S_ISDIR(old_dentry->d_inode->i_mode))
55 +       if (S_ISDIR(old_dentry->d_inode->i_mode) && !(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);