mtd: fix build with GCC 14
[openwrt/openwrt.git] / target / linux / generic / pending-5.15 / 140-jffs2-use-.rename2-and-add-RENAME_WHITEOUT-support.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: jffs2: use .rename2 and add RENAME_WHITEOUT support
3
4 It is required for renames on overlayfs
5
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8
9 --- a/fs/jffs2/dir.c
10 +++ b/fs/jffs2/dir.c
11 @@ -614,8 +614,8 @@ static int jffs2_rmdir (struct inode *di
12 return ret;
13 }
14
15 -static int jffs2_mknod (struct user_namespace *mnt_userns, struct inode *dir_i,
16 - struct dentry *dentry, umode_t mode, dev_t rdev)
17 +static int __jffs2_mknod (struct user_namespace *mnt_userns, struct inode *dir_i,
18 + struct dentry *dentry, umode_t mode, dev_t rdev, bool whiteout)
19 {
20 struct jffs2_inode_info *f, *dir_f;
21 struct jffs2_sb_info *c;
22 @@ -754,7 +754,11 @@ static int jffs2_mknod (struct user_name
23 mutex_unlock(&dir_f->sem);
24 jffs2_complete_reservation(c);
25
26 - d_instantiate_new(dentry, inode);
27 + if (!whiteout)
28 + d_instantiate_new(dentry, inode);
29 + else
30 + unlock_new_inode(inode);
31 +
32 return 0;
33
34 fail:
35 @@ -762,6 +766,19 @@ static int jffs2_mknod (struct user_name
36 return ret;
37 }
38
39 +static int jffs2_mknod (struct user_namespace *mnt_userns, struct inode *dir_i,
40 + struct dentry *dentry, umode_t mode, dev_t rdev)
41 +{
42 + return __jffs2_mknod(mnt_userns, dir_i, dentry, mode, rdev, false);
43 +}
44 +
45 +static int jffs2_whiteout (struct user_namespace *mnt_userns, struct inode *old_dir,
46 + struct dentry *old_dentry)
47 +{
48 + return __jffs2_mknod(mnt_userns, old_dir, old_dentry, S_IFCHR | WHITEOUT_MODE,
49 + WHITEOUT_DEV, true);
50 +}
51 +
52 static int jffs2_rename (struct user_namespace *mnt_userns,
53 struct inode *old_dir_i, struct dentry *old_dentry,
54 struct inode *new_dir_i, struct dentry *new_dentry,
55 @@ -773,7 +790,7 @@ static int jffs2_rename (struct user_nam
56 uint8_t type;
57 uint32_t now;
58
59 - if (flags & ~RENAME_NOREPLACE)
60 + if (flags & ~(RENAME_NOREPLACE|RENAME_WHITEOUT))
61 return -EINVAL;
62
63 /* The VFS will check for us and prevent trying to rename a
64 @@ -839,9 +856,14 @@ static int jffs2_rename (struct user_nam
65 if (d_is_dir(old_dentry) && !victim_f)
66 inc_nlink(new_dir_i);
67
68 - /* Unlink the original */
69 - ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
70 - old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
71 + if (flags & RENAME_WHITEOUT)
72 + /* Replace with whiteout */
73 + ret = jffs2_whiteout(mnt_userns, old_dir_i, old_dentry);
74 + else
75 + /* Unlink the original */
76 + ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
77 + old_dentry->d_name.name,
78 + old_dentry->d_name.len, NULL, now);
79
80 /* We don't touch inode->i_nlink */
81