2
0

111-jffs2-add-RENAME_EXCHANGE-support.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  5. ---
  6. --- a/fs/jffs2/dir.c
  7. +++ b/fs/jffs2/dir.c
  8. @@ -779,18 +779,31 @@ static int jffs2_rename (struct inode *o
  9. int ret;
  10. struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
  11. struct jffs2_inode_info *victim_f = NULL;
  12. + struct inode *fst_inode = d_inode(old_dentry);
  13. + struct inode *snd_inode = d_inode(new_dentry);
  14. uint8_t type;
  15. uint32_t now;
  16. - if (flags & ~RENAME_WHITEOUT)
  17. + if (flags & ~(RENAME_WHITEOUT | RENAME_EXCHANGE))
  18. return -EINVAL;
  19. + if ((flags & RENAME_EXCHANGE) && (old_dir_i != new_dir_i)) {
  20. + if (S_ISDIR(fst_inode->i_mode) && !S_ISDIR(snd_inode->i_mode)) {
  21. + inc_nlink(new_dir_i);
  22. + drop_nlink(old_dir_i);
  23. + }
  24. + else if (!S_ISDIR(fst_inode->i_mode) && S_ISDIR(snd_inode->i_mode)) {
  25. + drop_nlink(new_dir_i);
  26. + inc_nlink(old_dir_i);
  27. + }
  28. + }
  29. +
  30. /* The VFS will check for us and prevent trying to rename a
  31. * file over a directory and vice versa, but if it's a directory,
  32. * the VFS can't check whether the victim is empty. The filesystem
  33. * needs to do that for itself.
  34. */
  35. - if (d_really_is_positive(new_dentry)) {
  36. + if (d_really_is_positive(new_dentry) && !(flags & RENAME_EXCHANGE)) {
  37. victim_f = JFFS2_INODE_INFO(d_inode(new_dentry));
  38. if (d_is_dir(new_dentry)) {
  39. struct jffs2_full_dirent *fd;
  40. @@ -825,7 +838,7 @@ static int jffs2_rename (struct inode *o
  41. if (ret)
  42. return ret;
  43. - if (victim_f) {
  44. + if (victim_f && !(flags & RENAME_EXCHANGE)) {
  45. /* There was a victim. Kill it off nicely */
  46. if (d_is_dir(new_dentry))
  47. clear_nlink(d_inode(new_dentry));
  48. @@ -845,12 +858,18 @@ static int jffs2_rename (struct inode *o
  49. /* If it was a directory we moved, and there was no victim,
  50. increase i_nlink on its new parent */
  51. - if (d_is_dir(old_dentry) && !victim_f)
  52. + if (d_is_dir(old_dentry) && !victim_f && !(flags & RENAME_EXCHANGE))
  53. inc_nlink(new_dir_i);
  54. if (flags & RENAME_WHITEOUT)
  55. /* Replace with whiteout */
  56. ret = jffs2_whiteout(old_dir_i, old_dentry);
  57. + else if (flags & RENAME_EXCHANGE)
  58. + /* Replace the original */
  59. + ret = jffs2_do_link(c, JFFS2_INODE_INFO(old_dir_i),
  60. + d_inode(new_dentry)->i_ino, type,
  61. + old_dentry->d_name.name, old_dentry->d_name.len,
  62. + now);
  63. else
  64. /* Unlink the original */
  65. ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
  66. @@ -882,7 +901,7 @@ static int jffs2_rename (struct inode *o
  67. return ret;
  68. }
  69. - if (d_is_dir(old_dentry))
  70. + if (d_is_dir(old_dentry) && !(flags & RENAME_EXCHANGE))
  71. drop_nlink(old_dir_i);
  72. new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = ITIME(now);