blob: 411a9a9258b695927aee6ef02496d5eee302fc0a [file] [log] [blame]
Daniel Campello35c9e242015-07-20 16:23:50 -07001/*
2 * fs/sdcardfs/derived_perm.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
21#include "sdcardfs.h"
22
23/* copy derived state from parent inode */
24static void inherit_derived_state(struct inode *parent, struct inode *child)
25{
26 struct sdcardfs_inode_info *pi = SDCARDFS_I(parent);
27 struct sdcardfs_inode_info *ci = SDCARDFS_I(child);
28
29 ci->perm = PERM_INHERIT;
30 ci->userid = pi->userid;
31 ci->d_uid = pi->d_uid;
Daniel Rosenberg497ac902016-02-03 21:08:21 -080032 ci->under_android = pi->under_android;
Daniel Rosenbergad905252017-01-25 13:48:45 -080033 ci->under_cache = pi->under_cache;
34 ci->under_obb = pi->under_obb;
Daniel Rosenberg5080d242016-05-18 16:57:10 -070035 set_top(ci, pi->top);
Daniel Campello35c9e242015-07-20 16:23:50 -070036}
37
38/* helper function for derived state */
Daniel Rosenberg5080d242016-05-18 16:57:10 -070039void setup_derived_state(struct inode *inode, perm_t perm, userid_t userid,
Daniel Rosenberg5e024f62017-03-16 17:42:58 -070040 uid_t uid, bool under_android,
41 struct inode *top)
Daniel Campello35c9e242015-07-20 16:23:50 -070042{
43 struct sdcardfs_inode_info *info = SDCARDFS_I(inode);
44
45 info->perm = perm;
46 info->userid = userid;
47 info->d_uid = uid;
Daniel Rosenberg497ac902016-02-03 21:08:21 -080048 info->under_android = under_android;
Daniel Rosenbergad905252017-01-25 13:48:45 -080049 info->under_cache = false;
50 info->under_obb = false;
Daniel Rosenberg5080d242016-05-18 16:57:10 -070051 set_top(info, top);
Daniel Campello35c9e242015-07-20 16:23:50 -070052}
53
Daniel Rosenberg5e024f62017-03-16 17:42:58 -070054/* While renaming, there is a point where we want the path from dentry,
55 * but the name from newdentry
56 */
57void get_derived_permission_new(struct dentry *parent, struct dentry *dentry,
58 const struct qstr *name)
Daniel Campello35c9e242015-07-20 16:23:50 -070059{
Daniel Rosenberg63d20762016-12-01 14:36:29 -080060 struct sdcardfs_inode_info *info = SDCARDFS_I(d_inode(dentry));
Daniel Rosenberg5e024f62017-03-16 17:42:58 -070061 struct sdcardfs_inode_info *parent_info = SDCARDFS_I(d_inode(parent));
Daniel Campello35c9e242015-07-20 16:23:50 -070062 appid_t appid;
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -080063 struct qstr q_Android = QSTR_LITERAL("Android");
64 struct qstr q_data = QSTR_LITERAL("data");
65 struct qstr q_obb = QSTR_LITERAL("obb");
66 struct qstr q_media = QSTR_LITERAL("media");
67 struct qstr q_cache = QSTR_LITERAL("cache");
Daniel Campello35c9e242015-07-20 16:23:50 -070068
69 /* By default, each inode inherits from its parent.
70 * the properties are maintained on its private fields
71 * because the inode attributes will be modified with that of
72 * its lower inode.
Daniel Rosenbergad905252017-01-25 13:48:45 -080073 * These values are used by our custom permission call instead
74 * of using the inode permissions.
Daniel Campello35c9e242015-07-20 16:23:50 -070075 */
76
Daniel Rosenberg63d20762016-12-01 14:36:29 -080077 inherit_derived_state(d_inode(parent), d_inode(dentry));
Daniel Campello35c9e242015-07-20 16:23:50 -070078
Daniel Rosenbergad905252017-01-25 13:48:45 -080079 /* Files don't get special labels */
80 if (!S_ISDIR(d_inode(dentry)->i_mode))
81 return;
Daniel Campello35c9e242015-07-20 16:23:50 -070082 /* Derive custom permissions based on parent and current node */
83 switch (parent_info->perm) {
Daniel Rosenbergad905252017-01-25 13:48:45 -080084 case PERM_INHERIT:
85 case PERM_ANDROID_PACKAGE_CACHE:
86 /* Already inherited above */
87 break;
88 case PERM_PRE_ROOT:
89 /* Legacy internal layout places users at top level */
90 info->perm = PERM_ROOT;
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -080091 info->userid = simple_strtoul(name->name, NULL, 10);
Daniel Rosenbergad905252017-01-25 13:48:45 -080092 set_top(info, &info->vfs_inode);
93 break;
94 case PERM_ROOT:
95 /* Assume masked off by default. */
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -080096 if (qstr_case_eq(name, &q_Android)) {
Daniel Rosenbergad905252017-01-25 13:48:45 -080097 /* App-specific directories inside; let anyone traverse */
98 info->perm = PERM_ANDROID;
99 info->under_android = true;
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700100 set_top(info, &info->vfs_inode);
Daniel Rosenbergad905252017-01-25 13:48:45 -0800101 }
102 break;
103 case PERM_ANDROID:
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800104 if (qstr_case_eq(name, &q_data)) {
Daniel Rosenbergad905252017-01-25 13:48:45 -0800105 /* App-specific directories inside; let anyone traverse */
106 info->perm = PERM_ANDROID_DATA;
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700107 set_top(info, &info->vfs_inode);
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800108 } else if (qstr_case_eq(name, &q_obb)) {
Daniel Rosenbergad905252017-01-25 13:48:45 -0800109 /* App-specific directories inside; let anyone traverse */
110 info->perm = PERM_ANDROID_OBB;
111 info->under_obb = true;
112 set_top(info, &info->vfs_inode);
113 /* Single OBB directory is always shared */
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800114 } else if (qstr_case_eq(name, &q_media)) {
Daniel Rosenbergad905252017-01-25 13:48:45 -0800115 /* App-specific directories inside; let anyone traverse */
116 info->perm = PERM_ANDROID_MEDIA;
117 set_top(info, &info->vfs_inode);
118 }
119 break;
120 case PERM_ANDROID_OBB:
121 case PERM_ANDROID_DATA:
122 case PERM_ANDROID_MEDIA:
123 info->perm = PERM_ANDROID_PACKAGE;
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800124 appid = get_appid(name->name);
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700125 if (appid != 0 && !is_excluded(name->name, parent_info->userid))
Daniel Rosenbergad905252017-01-25 13:48:45 -0800126 info->d_uid = multiuser_get_uid(parent_info->userid, appid);
Daniel Rosenbergad905252017-01-25 13:48:45 -0800127 set_top(info, &info->vfs_inode);
128 break;
129 case PERM_ANDROID_PACKAGE:
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800130 if (qstr_case_eq(name, &q_cache)) {
Daniel Rosenbergad905252017-01-25 13:48:45 -0800131 info->perm = PERM_ANDROID_PACKAGE_CACHE;
132 info->under_cache = true;
133 }
134 break;
Daniel Campello35c9e242015-07-20 16:23:50 -0700135 }
136}
137
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800138void get_derived_permission(struct dentry *parent, struct dentry *dentry)
139{
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800140 get_derived_permission_new(parent, dentry, &dentry->d_name);
Daniel Rosenbergad905252017-01-25 13:48:45 -0800141}
142
143static appid_t get_type(const char *name)
144{
145 const char *ext = strrchr(name, '.');
146 appid_t id;
147
148 if (ext && ext[0]) {
149 ext = &ext[1];
150 id = get_ext_gid(ext);
151 return id?:AID_MEDIA_RW;
152 }
153 return AID_MEDIA_RW;
154}
155
156void fixup_lower_ownership(struct dentry *dentry, const char *name)
157{
158 struct path path;
159 struct inode *inode;
160 struct inode *delegated_inode = NULL;
161 int error;
162 struct sdcardfs_inode_info *info;
163 struct sdcardfs_inode_info *info_top;
164 perm_t perm;
165 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
166 uid_t uid = sbi->options.fs_low_uid;
167 gid_t gid = sbi->options.fs_low_gid;
168 struct iattr newattrs;
169
170 info = SDCARDFS_I(d_inode(dentry));
171 perm = info->perm;
172 if (info->under_obb) {
173 perm = PERM_ANDROID_OBB;
174 } else if (info->under_cache) {
175 perm = PERM_ANDROID_PACKAGE_CACHE;
176 } else if (perm == PERM_INHERIT) {
177 info_top = SDCARDFS_I(grab_top(info));
178 perm = info_top->perm;
179 release_top(info);
180 }
181
182 switch (perm) {
183 case PERM_ROOT:
184 case PERM_ANDROID:
185 case PERM_ANDROID_DATA:
186 case PERM_ANDROID_MEDIA:
187 case PERM_ANDROID_PACKAGE:
188 case PERM_ANDROID_PACKAGE_CACHE:
189 uid = multiuser_get_uid(info->userid, uid);
190 break;
191 case PERM_ANDROID_OBB:
192 uid = AID_MEDIA_OBB;
193 break;
194 case PERM_PRE_ROOT:
195 default:
196 break;
197 }
198 switch (perm) {
199 case PERM_ROOT:
200 case PERM_ANDROID:
201 case PERM_ANDROID_DATA:
202 case PERM_ANDROID_MEDIA:
203 if (S_ISDIR(d_inode(dentry)->i_mode))
204 gid = multiuser_get_uid(info->userid, AID_MEDIA_RW);
205 else
206 gid = multiuser_get_uid(info->userid, get_type(name));
207 break;
208 case PERM_ANDROID_OBB:
209 gid = AID_MEDIA_OBB;
210 break;
211 case PERM_ANDROID_PACKAGE:
212 if (info->d_uid != 0)
Daniel Rosenberg1ec14332017-03-13 15:34:03 -0700213 gid = multiuser_get_ext_gid(info->d_uid);
Daniel Rosenbergad905252017-01-25 13:48:45 -0800214 else
215 gid = multiuser_get_uid(info->userid, uid);
216 break;
217 case PERM_ANDROID_PACKAGE_CACHE:
218 if (info->d_uid != 0)
Daniel Rosenberg1ec14332017-03-13 15:34:03 -0700219 gid = multiuser_get_cache_gid(info->d_uid);
Daniel Rosenbergad905252017-01-25 13:48:45 -0800220 else
221 gid = multiuser_get_uid(info->userid, uid);
222 break;
223 case PERM_PRE_ROOT:
224 default:
225 break;
226 }
227
228 sdcardfs_get_lower_path(dentry, &path);
229 inode = d_inode(path.dentry);
230 if (d_inode(path.dentry)->i_gid.val != gid || d_inode(path.dentry)->i_uid.val != uid) {
231retry_deleg:
232 newattrs.ia_valid = ATTR_GID | ATTR_UID | ATTR_FORCE;
233 newattrs.ia_uid = make_kuid(current_user_ns(), uid);
234 newattrs.ia_gid = make_kgid(current_user_ns(), gid);
235 if (!S_ISDIR(inode->i_mode))
236 newattrs.ia_valid |=
237 ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV;
238 inode_lock(inode);
239 error = security_path_chown(&path, newattrs.ia_uid, newattrs.ia_gid);
240 if (!error)
241 error = notify_change2(path.mnt, path.dentry, &newattrs, &delegated_inode);
242 inode_unlock(inode);
243 if (delegated_inode) {
244 error = break_deleg_wait(&delegated_inode);
245 if (!error)
246 goto retry_deleg;
247 }
248 if (error)
249 pr_err("sdcardfs: Failed to touch up lower fs gid/uid.\n");
250 }
Daniel Rosenbergf61bc5a2017-02-16 17:55:22 -0800251 sdcardfs_put_lower_path(dentry, &path);
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800252}
253
Daniel Rosenbergd8caaf92017-01-22 15:32:49 -0800254static int descendant_may_need_fixup(struct sdcardfs_inode_info *info, struct limit_search *limit)
255{
256 if (info->perm == PERM_ROOT)
257 return (limit->flags & BY_USERID)?info->userid == limit->userid:1;
258 if (info->perm == PERM_PRE_ROOT || info->perm == PERM_ANDROID)
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700259 return 1;
260 return 0;
261}
262
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700263static int needs_fixup(perm_t perm)
264{
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700265 if (perm == PERM_ANDROID_DATA || perm == PERM_ANDROID_OBB
266 || perm == PERM_ANDROID_MEDIA)
267 return 1;
268 return 0;
269}
270
Daniel Rosenbergfb4d1912017-03-02 15:11:27 -0800271static void __fixup_perms_recursive(struct dentry *dentry, struct limit_search *limit, int depth)
Daniel Rosenbergd8caaf92017-01-22 15:32:49 -0800272{
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700273 struct dentry *child;
274 struct sdcardfs_inode_info *info;
Daniel Rosenbergfb4d1912017-03-02 15:11:27 -0800275
276 /*
277 * All paths will terminate their recursion on hitting PERM_ANDROID_OBB,
278 * PERM_ANDROID_MEDIA, or PERM_ANDROID_DATA. This happens at a depth of
279 * at most 3.
280 */
281 WARN(depth > 3, "%s: Max expected depth exceeded!\n", __func__);
282 spin_lock_nested(&dentry->d_lock, depth);
Daniel Rosenberg63d20762016-12-01 14:36:29 -0800283 if (!d_inode(dentry)) {
Daniel Rosenbergfb4d1912017-03-02 15:11:27 -0800284 spin_unlock(&dentry->d_lock);
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700285 return;
286 }
287 info = SDCARDFS_I(d_inode(dentry));
288
289 if (needs_fixup(info->perm)) {
Daniel Rosenberg3adfc032016-12-27 12:36:29 -0800290 list_for_each_entry(child, &dentry->d_subdirs, d_child) {
Daniel Rosenbergfb4d1912017-03-02 15:11:27 -0800291 spin_lock_nested(&child->d_lock, depth + 1);
Daniel Rosenberg721274a2017-03-08 17:20:02 -0800292 if (!(limit->flags & BY_NAME) || qstr_case_eq(&child->d_name, &limit->name)) {
Daniel Rosenbergd8caaf92017-01-22 15:32:49 -0800293 if (d_inode(child)) {
294 get_derived_permission(dentry, child);
295 fixup_tmp_permissions(d_inode(child));
Daniel Rosenbergfb4d1912017-03-02 15:11:27 -0800296 spin_unlock(&child->d_lock);
Daniel Rosenbergd8caaf92017-01-22 15:32:49 -0800297 break;
Daniel Rosenberg3adfc032016-12-27 12:36:29 -0800298 }
Daniel Rosenbergd8caaf92017-01-22 15:32:49 -0800299 }
Daniel Rosenbergfb4d1912017-03-02 15:11:27 -0800300 spin_unlock(&child->d_lock);
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700301 }
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700302 } else if (descendant_may_need_fixup(info, limit)) {
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700303 list_for_each_entry(child, &dentry->d_subdirs, d_child) {
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700304 __fixup_perms_recursive(child, limit, depth + 1);
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700305 }
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700306 }
Daniel Rosenbergfb4d1912017-03-02 15:11:27 -0800307 spin_unlock(&dentry->d_lock);
308}
309
310void fixup_perms_recursive(struct dentry *dentry, struct limit_search *limit)
311{
312 __fixup_perms_recursive(dentry, limit, 0);
Daniel Rosenberg5080d242016-05-18 16:57:10 -0700313}
314
Daniel Campello35c9e242015-07-20 16:23:50 -0700315/* main function for updating derived permission */
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800316inline void update_derived_permission_lock(struct dentry *dentry)
Daniel Campello35c9e242015-07-20 16:23:50 -0700317{
318 struct dentry *parent;
319
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700320 if (!dentry || !d_inode(dentry)) {
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700321 pr_err("sdcardfs: %s: invalid dentry\n", __func__);
Daniel Campello35c9e242015-07-20 16:23:50 -0700322 return;
323 }
324 /* FIXME:
325 * 1. need to check whether the dentry is updated or not
326 * 2. remove the root dentry update
327 */
Daniel Rosenbergd64126c2017-03-16 19:33:35 -0700328 if (!IS_ROOT(dentry)) {
Daniel Campello35c9e242015-07-20 16:23:50 -0700329 parent = dget_parent(dentry);
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700330 if (parent) {
Daniel Campello35c9e242015-07-20 16:23:50 -0700331 get_derived_permission(parent, dentry);
332 dput(parent);
333 }
334 }
Daniel Rosenberg90219272016-10-26 20:27:20 -0700335 fixup_tmp_permissions(d_inode(dentry));
Daniel Campello35c9e242015-07-20 16:23:50 -0700336}
337
338int need_graft_path(struct dentry *dentry)
339{
340 int ret = 0;
341 struct dentry *parent = dget_parent(dentry);
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700342 struct sdcardfs_inode_info *parent_info = SDCARDFS_I(d_inode(parent));
Daniel Campello35c9e242015-07-20 16:23:50 -0700343 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800344 struct qstr obb = QSTR_LITERAL("obb");
Daniel Campello35c9e242015-07-20 16:23:50 -0700345
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700346 if (parent_info->perm == PERM_ANDROID &&
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800347 qstr_case_eq(&dentry->d_name, &obb)) {
Daniel Campello35c9e242015-07-20 16:23:50 -0700348
349 /* /Android/obb is the base obbpath of DERIVED_UNIFIED */
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700350 if (!(sbi->options.multiuser == false
Daniel Campello35c9e242015-07-20 16:23:50 -0700351 && parent_info->userid == 0)) {
352 ret = 1;
353 }
354 }
355 dput(parent);
356 return ret;
357}
358
359int is_obbpath_invalid(struct dentry *dent)
360{
361 int ret = 0;
362 struct sdcardfs_dentry_info *di = SDCARDFS_D(dent);
363 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dent->d_sb);
364 char *path_buf, *obbpath_s;
Daniel Rosenberge2538da2017-03-10 13:54:30 -0800365 int need_put = 0;
366 struct path lower_path;
Daniel Campello35c9e242015-07-20 16:23:50 -0700367
368 /* check the base obbpath has been changed.
369 * this routine can check an uninitialized obb dentry as well.
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700370 * regarding the uninitialized obb, refer to the sdcardfs_mkdir()
371 */
Daniel Campello35c9e242015-07-20 16:23:50 -0700372 spin_lock(&di->lock);
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700373 if (di->orig_path.dentry) {
374 if (!di->lower_path.dentry) {
Daniel Campello35c9e242015-07-20 16:23:50 -0700375 ret = 1;
376 } else {
377 path_get(&di->lower_path);
Daniel Campello35c9e242015-07-20 16:23:50 -0700378
379 path_buf = kmalloc(PATH_MAX, GFP_ATOMIC);
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700380 if (!path_buf) {
Daniel Campello35c9e242015-07-20 16:23:50 -0700381 ret = 1;
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700382 pr_err("sdcardfs: fail to allocate path_buf in %s.\n", __func__);
Daniel Campello35c9e242015-07-20 16:23:50 -0700383 } else {
384 obbpath_s = d_path(&di->lower_path, path_buf, PATH_MAX);
385 if (d_unhashed(di->lower_path.dentry) ||
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800386 !str_case_eq(sbi->obbpath_s, obbpath_s)) {
Daniel Campello35c9e242015-07-20 16:23:50 -0700387 ret = 1;
388 }
389 kfree(path_buf);
390 }
391
Daniel Rosenberge2538da2017-03-10 13:54:30 -0800392 pathcpy(&lower_path, &di->lower_path);
393 need_put = 1;
Daniel Campello35c9e242015-07-20 16:23:50 -0700394 }
395 }
396 spin_unlock(&di->lock);
Daniel Rosenberge2538da2017-03-10 13:54:30 -0800397 if (need_put)
398 path_put(&lower_path);
Daniel Campello35c9e242015-07-20 16:23:50 -0700399 return ret;
400}
401
402int is_base_obbpath(struct dentry *dentry)
403{
404 int ret = 0;
405 struct dentry *parent = dget_parent(dentry);
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700406 struct sdcardfs_inode_info *parent_info = SDCARDFS_I(d_inode(parent));
Daniel Campello35c9e242015-07-20 16:23:50 -0700407 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800408 struct qstr q_obb = QSTR_LITERAL("obb");
Daniel Campello35c9e242015-07-20 16:23:50 -0700409
410 spin_lock(&SDCARDFS_D(dentry)->lock);
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800411 if (sbi->options.multiuser) {
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700412 if (parent_info->perm == PERM_PRE_ROOT &&
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800413 qstr_case_eq(&dentry->d_name, &q_obb)) {
Daniel Rosenberg497ac902016-02-03 21:08:21 -0800414 ret = 1;
415 }
416 } else if (parent_info->perm == PERM_ANDROID &&
Daniel Rosenberg5004c5f2017-01-31 20:07:51 -0800417 qstr_case_eq(&dentry->d_name, &q_obb)) {
Daniel Campello35c9e242015-07-20 16:23:50 -0700418 ret = 1;
419 }
Daniel Campello35c9e242015-07-20 16:23:50 -0700420 spin_unlock(&SDCARDFS_D(dentry)->lock);
Daniel Campello35c9e242015-07-20 16:23:50 -0700421 return ret;
422}
423
424/* The lower_path will be stored to the dentry's orig_path
425 * and the base obbpath will be copyed to the lower_path variable.
426 * if an error returned, there's no change in the lower_path
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700427 * returns: -ERRNO if error (0: no error)
428 */
Daniel Campello35c9e242015-07-20 16:23:50 -0700429int setup_obb_dentry(struct dentry *dentry, struct path *lower_path)
430{
431 int err = 0;
432 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
433 struct path obbpath;
434
435 /* A local obb dentry must have its own orig_path to support rmdir
436 * and mkdir of itself. Usually, we expect that the sbi->obbpath
Daniel Rosenbergd64126c2017-03-16 19:33:35 -0700437 * is avaiable on this stage.
438 */
Daniel Campello35c9e242015-07-20 16:23:50 -0700439 sdcardfs_set_orig_path(dentry, lower_path);
440
441 err = kern_path(sbi->obbpath_s,
442 LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &obbpath);
443
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700444 if (!err) {
Daniel Campello35c9e242015-07-20 16:23:50 -0700445 /* the obbpath base has been found */
Daniel Campello35c9e242015-07-20 16:23:50 -0700446 pathcpy(lower_path, &obbpath);
447 } else {
448 /* if the sbi->obbpath is not available, we can optionally
449 * setup the lower_path with its orig_path.
450 * but, the current implementation just returns an error
451 * because the sdcard daemon also regards this case as
Daniel Rosenberg5e024f62017-03-16 17:42:58 -0700452 * a lookup fail.
453 */
Daniel Rosenberg77ecf212017-03-16 17:46:13 -0700454 pr_info("sdcardfs: the sbi->obbpath is not available\n");
Daniel Campello35c9e242015-07-20 16:23:50 -0700455 }
456 return err;
457}
458
459