110-jffs2-use-.rename2-and-add-RENAME_WHITEOUT-support.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Fri, 10 Apr 2015 13:35:29 +0200
  3. Subject: [PATCH] jffs2: use .rename2 and add RENAME_WHITEOUT support
  4. It is required for renames on overlayfs
  5. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  6. ---
  7. --- a/fs/jffs2/dir.c
  8. +++ b/fs/jffs2/dir.c
  9. @@ -35,7 +35,7 @@ static int jffs2_mkdir (struct inode *,s
  10. static int jffs2_rmdir (struct inode *,struct dentry *);
  11. static int jffs2_mknod (struct inode *,struct dentry *,umode_t,dev_t);
  12. static int jffs2_rename (struct inode *, struct dentry *,
  13. - struct inode *, struct dentry *);
  14. + struct inode *, struct dentry *, unsigned int);
  15. const struct file_operations jffs2_dir_operations =
  16. {
  17. @@ -57,7 +57,7 @@ const struct inode_operations jffs2_dir_
  18. .mkdir = jffs2_mkdir,
  19. .rmdir = jffs2_rmdir,
  20. .mknod = jffs2_mknod,
  21. - .rename = jffs2_rename,
  22. + .rename2 = jffs2_rename,
  23. .get_acl = jffs2_get_acl,
  24. .set_acl = jffs2_set_acl,
  25. .setattr = jffs2_setattr,
  26. @@ -754,8 +754,27 @@ static int jffs2_mknod (struct inode *di
  27. return ret;
  28. }
  29. +static int jffs2_whiteout(struct inode *old_dir, struct dentry *old_dentry)
  30. +{
  31. + struct dentry *wh;
  32. + int err;
  33. +
  34. + wh = d_alloc(old_dentry->d_parent, &old_dentry->d_name);
  35. + if (!wh)
  36. + return -ENOMEM;
  37. +
  38. + err = jffs2_mknod(old_dir, wh, S_IFCHR | WHITEOUT_MODE,
  39. + WHITEOUT_DEV);
  40. + if (err)
  41. + return err;
  42. +
  43. + d_rehash(wh);
  44. + return 0;
  45. +}
  46. +
  47. static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
  48. - struct inode *new_dir_i, struct dentry *new_dentry)
  49. + struct inode *new_dir_i, struct dentry *new_dentry,
  50. + unsigned int flags)
  51. {
  52. int ret;
  53. struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
  54. @@ -763,6 +782,9 @@ static int jffs2_rename (struct inode *o
  55. uint8_t type;
  56. uint32_t now;
  57. + if (flags & ~RENAME_WHITEOUT)
  58. + return -EINVAL;
  59. +
  60. /* The VFS will check for us and prevent trying to rename a
  61. * file over a directory and vice versa, but if it's a directory,
  62. * the VFS can't check whether the victim is empty. The filesystem
  63. @@ -826,9 +848,14 @@ static int jffs2_rename (struct inode *o
  64. if (d_is_dir(old_dentry) && !victim_f)
  65. inc_nlink(new_dir_i);
  66. - /* Unlink the original */
  67. - ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
  68. - old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
  69. + if (flags & RENAME_WHITEOUT)
  70. + /* Replace with whiteout */
  71. + ret = jffs2_whiteout(old_dir_i, old_dentry);
  72. + else
  73. + /* Unlink the original */
  74. + ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
  75. + old_dentry->d_name.name,
  76. + old_dentry->d_name.len, NULL, now);
  77. /* We don't touch inode->i_nlink */