140-jffs2-use-.rename2-and-add-RENAME_WHITEOUT-support.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Subject: jffs2: use .rename2 and add RENAME_WHITEOUT support
  3. It is required for renames on overlayfs
  4. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  5. ---
  6. --- a/fs/jffs2/dir.c
  7. +++ b/fs/jffs2/dir.c
  8. @@ -752,6 +752,24 @@ static int jffs2_mknod (struct inode *di
  9. return ret;
  10. }
  11. +static int jffs2_whiteout (struct inode *old_dir, struct dentry *old_dentry)
  12. +{
  13. + struct dentry *wh;
  14. + int err;
  15. +
  16. + wh = d_alloc(old_dentry->d_parent, &old_dentry->d_name);
  17. + if (!wh)
  18. + return -ENOMEM;
  19. +
  20. + err = jffs2_mknod(old_dir, wh, S_IFCHR | WHITEOUT_MODE,
  21. + WHITEOUT_DEV);
  22. + if (err)
  23. + return err;
  24. +
  25. + d_rehash(wh);
  26. + return 0;
  27. +}
  28. +
  29. static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
  30. struct inode *new_dir_i, struct dentry *new_dentry,
  31. unsigned int flags)
  32. @@ -762,7 +780,7 @@ static int jffs2_rename (struct inode *o
  33. uint8_t type;
  34. uint32_t now;
  35. - if (flags & ~RENAME_NOREPLACE)
  36. + if (flags & ~(RENAME_NOREPLACE|RENAME_WHITEOUT))
  37. return -EINVAL;
  38. /* The VFS will check for us and prevent trying to rename a
  39. @@ -828,9 +846,14 @@ static int jffs2_rename (struct inode *o
  40. if (d_is_dir(old_dentry) && !victim_f)
  41. inc_nlink(new_dir_i);
  42. - /* Unlink the original */
  43. - ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
  44. - old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
  45. + if (flags & RENAME_WHITEOUT)
  46. + /* Replace with whiteout */
  47. + ret = jffs2_whiteout(old_dir_i, old_dentry);
  48. + else
  49. + /* Unlink the original */
  50. + ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
  51. + old_dentry->d_name.name,
  52. + old_dentry->d_name.len, NULL, now);
  53. /* We don't touch inode->i_nlink */