dentry.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * fs/sdcardfs/dentry.c
  3. *
  4. * Copyright (c) 2013 Samsung Electronics Co. Ltd
  5. * Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun,
  6. * Sunghwan Yun, Sungjong Seo
  7. *
  8. * This program has been developed as a stackable file system based on
  9. * the WrapFS which written by
  10. *
  11. * Copyright (c) 1998-2011 Erez Zadok
  12. * Copyright (c) 2009 Shrikar Archak
  13. * Copyright (c) 2003-2011 Stony Brook University
  14. * Copyright (c) 2003-2011 The Research Foundation of SUNY
  15. *
  16. * This file is dual licensed. It may be redistributed and/or modified
  17. * under the terms of the Apache 2.0 License OR version 2 of the GNU
  18. * General Public License.
  19. */
  20. #include "sdcardfs.h"
  21. #include "linux/ctype.h"
  22. /*
  23. * returns: -ERRNO if error (returned to user)
  24. * 0: tell VFS to invalidate dentry
  25. * 1: dentry is valid
  26. */
  27. static int sdcardfs_d_revalidate(struct dentry *dentry, unsigned int flags)
  28. {
  29. int err = 1;
  30. struct path parent_lower_path, lower_path;
  31. struct dentry *parent_dentry = NULL;
  32. struct dentry *parent_lower_dentry = NULL;
  33. struct dentry *lower_cur_parent_dentry = NULL;
  34. struct dentry *lower_dentry = NULL;
  35. struct inode *inode;
  36. struct sdcardfs_inode_data *data;
  37. if (flags & LOOKUP_RCU)
  38. return -ECHILD;
  39. spin_lock(&dentry->d_lock);
  40. if (IS_ROOT(dentry)) {
  41. spin_unlock(&dentry->d_lock);
  42. return 1;
  43. }
  44. spin_unlock(&dentry->d_lock);
  45. /* check uninitialized obb_dentry and
  46. * whether the base obbpath has been changed or not
  47. */
  48. if (is_obbpath_invalid(dentry)) {
  49. return 0;
  50. }
  51. parent_dentry = dget_parent(dentry);
  52. sdcardfs_get_lower_path(parent_dentry, &parent_lower_path);
  53. sdcardfs_get_real_lower(dentry, &lower_path);
  54. parent_lower_dentry = parent_lower_path.dentry;
  55. lower_dentry = lower_path.dentry;
  56. lower_cur_parent_dentry = dget_parent(lower_dentry);
  57. if ((lower_dentry->d_flags & DCACHE_OP_REVALIDATE)) {
  58. err = lower_dentry->d_op->d_revalidate(lower_dentry, flags);
  59. if (err == 0) {
  60. goto out;
  61. }
  62. }
  63. spin_lock(&lower_dentry->d_lock);
  64. if (d_unhashed(lower_dentry)) {
  65. spin_unlock(&lower_dentry->d_lock);
  66. err = 0;
  67. goto out;
  68. }
  69. spin_unlock(&lower_dentry->d_lock);
  70. if (parent_lower_dentry != lower_cur_parent_dentry) {
  71. err = 0;
  72. goto out;
  73. }
  74. if (dentry < lower_dentry) {
  75. spin_lock(&dentry->d_lock);
  76. spin_lock_nested(&lower_dentry->d_lock, DENTRY_D_LOCK_NESTED);
  77. } else {
  78. spin_lock(&lower_dentry->d_lock);
  79. spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
  80. }
  81. if (!qstr_case_eq(&dentry->d_name, &lower_dentry->d_name)) {
  82. err = 0;
  83. }
  84. if (dentry < lower_dentry) {
  85. spin_unlock(&lower_dentry->d_lock);
  86. spin_unlock(&dentry->d_lock);
  87. } else {
  88. spin_unlock(&dentry->d_lock);
  89. spin_unlock(&lower_dentry->d_lock);
  90. }
  91. if (!err)
  92. goto out;
  93. /* If our top's inode is gone, we may be out of date */
  94. inode = igrab(d_inode(dentry));
  95. if (inode) {
  96. data = top_data_get(SDCARDFS_I(inode));
  97. if (!data || data->abandoned) {
  98. err = 0;
  99. }
  100. if (data)
  101. data_put(data);
  102. iput(inode);
  103. }
  104. out:
  105. dput(parent_dentry);
  106. dput(lower_cur_parent_dentry);
  107. sdcardfs_put_lower_path(parent_dentry, &parent_lower_path);
  108. sdcardfs_put_real_lower(dentry, &lower_path);
  109. return err;
  110. }
  111. /* 1 = delete, 0 = cache */
  112. static int sdcardfs_d_delete(const struct dentry *d)
  113. {
  114. return SDCARDFS_SB(d->d_sb)->options.nocache ? 1 : 0;
  115. }
  116. static void sdcardfs_d_release(struct dentry *dentry)
  117. {
  118. if (!dentry || !dentry->d_fsdata)
  119. return;
  120. /* release and reset the lower paths */
  121. if (has_graft_path(dentry))
  122. sdcardfs_put_reset_orig_path(dentry);
  123. sdcardfs_put_reset_lower_path(dentry);
  124. free_dentry_private_data(dentry);
  125. }
  126. static int sdcardfs_hash_ci(const struct dentry *dentry,
  127. struct qstr *qstr)
  128. {
  129. /*
  130. * This function is copy of vfat_hashi.
  131. * FIXME Should we support national language?
  132. * Refer to vfat_hashi()
  133. * struct nls_table *t = MSDOS_SB(dentry->d_sb)->nls_io;
  134. */
  135. const unsigned char *name;
  136. unsigned int len;
  137. unsigned long hash;
  138. name = qstr->name;
  139. len = qstr->len;
  140. hash = init_name_hash(dentry);
  141. while (len--)
  142. hash = partial_name_hash(tolower(*name++), hash);
  143. qstr->hash = end_name_hash(hash);
  144. return 0;
  145. }
  146. /*
  147. * Case insensitive compare of two vfat names.
  148. */
  149. static int sdcardfs_cmp_ci(const struct dentry *dentry,
  150. unsigned int len, const char *str, const struct qstr *name)
  151. {
  152. /* FIXME Should we support national language? */
  153. if (name->len == len) {
  154. if (str_n_case_eq(name->name, str, len))
  155. return 0;
  156. }
  157. return 1;
  158. }
  159. static void sdcardfs_canonical_path(const struct path *path,
  160. struct path *actual_path)
  161. {
  162. sdcardfs_get_real_lower(path->dentry, actual_path);
  163. }
  164. const struct dentry_operations sdcardfs_ci_dops = {
  165. .d_revalidate = sdcardfs_d_revalidate,
  166. .d_delete = sdcardfs_d_delete,
  167. .d_release = sdcardfs_d_release,
  168. .d_hash = sdcardfs_hash_ci,
  169. .d_compare = sdcardfs_cmp_ci,
  170. .d_canonical_path = sdcardfs_canonical_path,
  171. };