4 * Copyright (c) 2013 Samsung Electronics Co. Ltd
5 * Authors: Daeho Jeong, Woojoong Lee, Seunghwan Hyun,
6 * Sunghwan Yun, Sungjong Seo
8 * This program has been developed as a stackable file system based on
9 * the WrapFS which written by
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
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.
22 #include "linux/ctype.h"
25 * returns: -ERRNO if error (returned to user)
26 * 0: tell VFS to invalidate dentry
29 static int sdcardfs_d_revalidate(struct dentry *dentry, unsigned int flags)
32 struct path parent_lower_path, lower_path;
33 struct dentry *parent_dentry = NULL;
34 struct dentry *parent_lower_dentry = NULL;
35 struct dentry *lower_cur_parent_dentry = NULL;
36 struct dentry *lower_dentry = NULL;
38 if (flags & LOOKUP_RCU)
41 spin_lock(&dentry->d_lock);
42 if (IS_ROOT(dentry)) {
43 spin_unlock(&dentry->d_lock);
46 spin_unlock(&dentry->d_lock);
48 /* check uninitialized obb_dentry and
49 * whether the base obbpath has been changed or not */
50 if (is_obbpath_invalid(dentry)) {
55 parent_dentry = dget_parent(dentry);
56 sdcardfs_get_lower_path(parent_dentry, &parent_lower_path);
57 sdcardfs_get_real_lower(dentry, &lower_path);
58 parent_lower_dentry = parent_lower_path.dentry;
59 lower_dentry = lower_path.dentry;
60 lower_cur_parent_dentry = dget_parent(lower_dentry);
62 spin_lock(&lower_dentry->d_lock);
63 if (d_unhashed(lower_dentry)) {
64 spin_unlock(&lower_dentry->d_lock);
69 spin_unlock(&lower_dentry->d_lock);
71 if (parent_lower_dentry != lower_cur_parent_dentry) {
77 if (dentry < lower_dentry) {
78 spin_lock(&dentry->d_lock);
79 spin_lock(&lower_dentry->d_lock);
81 spin_lock(&lower_dentry->d_lock);
82 spin_lock(&dentry->d_lock);
85 if (dentry->d_name.len != lower_dentry->d_name.len) {
88 } else if (strncasecmp(dentry->d_name.name, lower_dentry->d_name.name,
89 dentry->d_name.len) != 0) {
94 if (dentry < lower_dentry) {
95 spin_unlock(&lower_dentry->d_lock);
96 spin_unlock(&dentry->d_lock);
98 spin_unlock(&dentry->d_lock);
99 spin_unlock(&lower_dentry->d_lock);
104 dput(lower_cur_parent_dentry);
105 sdcardfs_put_lower_path(parent_dentry, &parent_lower_path);
106 sdcardfs_put_real_lower(dentry, &lower_path);
110 static void sdcardfs_d_release(struct dentry *dentry)
112 /* release and reset the lower paths */
113 if(has_graft_path(dentry)) {
114 sdcardfs_put_reset_orig_path(dentry);
116 sdcardfs_put_reset_lower_path(dentry);
117 free_dentry_private_data(dentry);
121 static int sdcardfs_hash_ci(const struct dentry *dentry,
125 * This function is copy of vfat_hashi.
126 * FIXME Should we support national language?
127 * Refer to vfat_hashi()
128 * struct nls_table *t = MSDOS_SB(dentry->d_sb)->nls_io;
130 const unsigned char *name;
135 //len = vfat_striptail_len(qstr);
138 hash = init_name_hash();
140 //hash = partial_name_hash(nls_tolower(t, *name++), hash);
141 hash = partial_name_hash(tolower(*name++), hash);
142 qstr->hash = end_name_hash(hash);
148 * Case insensitive compare of two vfat names.
150 static int sdcardfs_cmp_ci(const struct dentry *parent,
151 const struct dentry *dentry,
152 unsigned int len, const char *str, const struct qstr *name)
154 /* This function is copy of vfat_cmpi */
155 // FIXME Should we support national language?
156 //struct nls_table *t = MSDOS_SB(parent->d_sb)->nls_io;
157 //unsigned int alen, blen;
159 /* A filename cannot end in '.' or we treat it like it has none */
161 alen = vfat_striptail_len(name);
162 blen = __vfat_striptail_len(len, str);
164 if (nls_strnicmp(t, name->name, str, alen) == 0)
168 if (name->len == len) {
169 if (strncasecmp(name->name, str, len) == 0)
175 const struct dentry_operations sdcardfs_ci_dops = {
176 .d_revalidate = sdcardfs_d_revalidate,
177 .d_release = sdcardfs_d_release,
178 .d_hash = sdcardfs_hash_ci,
179 .d_compare = sdcardfs_cmp_ci,
180 .d_canonical_path = sdcardfs_get_real_lower,