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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. @@ -782,7 +782,7 @@ static int jffs2_rename (struct inode *o
  9. uint8_t type;
  10. uint32_t now;
  11. - if (flags & ~RENAME_WHITEOUT)
  12. + if (flags & ~(RENAME_WHITEOUT | RENAME_EXCHANGE))
  13. return -EINVAL;
  14. /* The VFS will check for us and prevent trying to rename a
  15. @@ -790,7 +790,7 @@ static int jffs2_rename (struct inode *o
  16. * the VFS can't check whether the victim is empty. The filesystem
  17. * needs to do that for itself.
  18. */
  19. - if (d_really_is_positive(new_dentry)) {
  20. + if (d_really_is_positive(new_dentry) && !(flags & RENAME_EXCHANGE)) {
  21. victim_f = JFFS2_INODE_INFO(d_inode(new_dentry));
  22. if (d_is_dir(new_dentry)) {
  23. struct jffs2_full_dirent *fd;
  24. @@ -825,7 +825,7 @@ static int jffs2_rename (struct inode *o
  25. if (ret)
  26. return ret;
  27. - if (victim_f) {
  28. + if (victim_f && !(flags & RENAME_EXCHANGE)) {
  29. /* There was a victim. Kill it off nicely */
  30. if (d_is_dir(new_dentry))
  31. clear_nlink(d_inode(new_dentry));
  32. @@ -851,6 +851,12 @@ static int jffs2_rename (struct inode *o
  33. if (flags & RENAME_WHITEOUT)
  34. /* Replace with whiteout */
  35. ret = jffs2_whiteout(old_dir_i, old_dentry);
  36. + else if (flags & RENAME_EXCHANGE)
  37. + /* Replace the original */
  38. + ret = jffs2_do_link(c, JFFS2_INODE_INFO(old_dir_i),
  39. + d_inode(new_dentry)->i_ino, type,
  40. + old_dentry->d_name.name, old_dentry->d_name.len,
  41. + now);
  42. else
  43. /* Unlink the original */
  44. ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
  45. @@ -882,7 +888,7 @@ static int jffs2_rename (struct inode *o
  46. return ret;
  47. }
  48. - if (d_is_dir(old_dentry))
  49. + if (d_is_dir(old_dentry) && !(flags & RENAME_EXCHANGE))
  50. drop_nlink(old_dir_i);
  51. new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = ITIME(now);