blob: 4e6de59675964bc84955c79bea5e6b038a3b7467 [file] [log] [blame]
Daniel Campello3a703812015-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 Rosenberg5c09ef42016-02-03 21:08:21 -080032 ci->under_android = pi->under_android;
Daniel Rosenbergb7c13d82017-01-25 13:48:45 -080033 ci->under_cache = pi->under_cache;
34 ci->under_obb = pi->under_obb;
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -070035 set_top(ci, pi->top);
Daniel Campello3a703812015-07-20 16:23:50 -070036}
37
38/* helper function for derived state */
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -070039void setup_derived_state(struct inode *inode, perm_t perm, userid_t userid,
Daniel Rosenbergbeb00302017-03-16 17:42:58 -070040 uid_t uid, bool under_android,
41 struct inode *top)
Daniel Campello3a703812015-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 Rosenberg5c09ef42016-02-03 21:08:21 -080048 info->under_android = under_android;
Daniel Rosenbergb7c13d82017-01-25 13:48:45 -080049 info->under_cache = false;
50 info->under_obb = false;
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -070051 set_top(info, top);
Daniel Campello3a703812015-07-20 16:23:50 -070052}
53
Daniel Rosenbergbeb00302017-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 Campello3a703812015-07-20 16:23:50 -070059{
Daniel Campello3a703812015-07-20 16:23:50 -070060 struct sdcardfs_inode_info *info = SDCARDFS_I(dentry->d_inode);
Daniel Rosenbergbeb00302017-03-16 17:42:58 -070061 struct sdcardfs_inode_info *parent_info = SDCARDFS_I(parent->d_inode);
Daniel Campello3a703812015-07-20 16:23:50 -070062 appid_t appid;
Daniel Rosenberg2d336b62017-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 Campello3a703812015-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 Rosenbergb7c13d82017-01-25 13:48:45 -080073 * These values are used by our custom permission call instead
74 * of using the inode permissions.
Daniel Campello3a703812015-07-20 16:23:50 -070075 */
76
77 inherit_derived_state(parent->d_inode, dentry->d_inode);
78
Daniel Rosenbergb7c13d82017-01-25 13:48:45 -080079 /* Files don't get special labels */
80 if (!S_ISDIR(dentry->d_inode->i_mode))
81 return;
Daniel Campello3a703812015-07-20 16:23:50 -070082 /* Derive custom permissions based on parent and current node */
83 switch (parent_info->perm) {
Daniel Rosenbergbeb00302017-03-16 17:42:58 -070084 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;
91 info->userid = simple_strtoul(name->name, NULL, 10);
92 set_top(info, &info->vfs_inode);
93 break;
94 case PERM_ROOT:
95 /* Assume masked off by default. */
96 if (qstr_case_eq(name, &q_Android)) {
97 /* App-specific directories inside; let anyone traverse */
98 info->perm = PERM_ANDROID;
99 info->under_android = true;
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700100 set_top(info, &info->vfs_inode);
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700101 }
102 break;
103 case PERM_ANDROID:
104 if (qstr_case_eq(name, &q_data)) {
105 /* App-specific directories inside; let anyone traverse */
106 info->perm = PERM_ANDROID_DATA;
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700107 set_top(info, &info->vfs_inode);
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700108 } else if (qstr_case_eq(name, &q_obb)) {
109 /* 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 */
114 } else if (qstr_case_eq(name, &q_media)) {
115 /* 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;
124 appid = get_appid(name->name);
125 if (appid != 0 && !is_excluded(name->name, parent_info->userid))
126 info->d_uid = multiuser_get_uid(parent_info->userid, appid);
127 set_top(info, &info->vfs_inode);
128 break;
129 case PERM_ANDROID_PACKAGE:
130 if (qstr_case_eq(name, &q_cache)) {
131 info->perm = PERM_ANDROID_PACKAGE_CACHE;
132 info->under_cache = true;
133 }
134 break;
Daniel Campello3a703812015-07-20 16:23:50 -0700135 }
136}
137
Daniel Rosenberg5c09ef42016-02-03 21:08:21 -0800138void get_derived_permission(struct dentry *parent, struct dentry *dentry)
139{
Daniel Rosenberg2d336b62017-01-31 20:07:51 -0800140 get_derived_permission_new(parent, dentry, &dentry->d_name);
Daniel Rosenbergb7c13d82017-01-25 13:48:45 -0800141}
142
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700143static appid_t get_type(const char *name)
144{
Daniel Rosenbergb7c13d82017-01-25 13:48:45 -0800145 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
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700156void fixup_lower_ownership(struct dentry *dentry, const char *name)
157{
Daniel Rosenbergb7c13d82017-01-25 13:48:45 -0800158 struct path path;
159 struct inode *inode;
160 int error;
161 struct sdcardfs_inode_info *info;
162 struct sdcardfs_inode_info *info_top;
163 perm_t perm;
164 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
165 uid_t uid = sbi->options.fs_low_uid;
166 gid_t gid = sbi->options.fs_low_gid;
167 struct iattr newattrs;
168
169 info = SDCARDFS_I(dentry->d_inode);
170 perm = info->perm;
171 if (info->under_obb) {
172 perm = PERM_ANDROID_OBB;
173 } else if (info->under_cache) {
174 perm = PERM_ANDROID_PACKAGE_CACHE;
175 } else if (perm == PERM_INHERIT) {
176 info_top = SDCARDFS_I(grab_top(info));
177 perm = info_top->perm;
178 release_top(info);
179 }
180
181 switch (perm) {
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700182 case PERM_ROOT:
183 case PERM_ANDROID:
184 case PERM_ANDROID_DATA:
185 case PERM_ANDROID_MEDIA:
186 case PERM_ANDROID_PACKAGE:
187 case PERM_ANDROID_PACKAGE_CACHE:
188 uid = multiuser_get_uid(info->userid, uid);
189 break;
190 case PERM_ANDROID_OBB:
191 uid = AID_MEDIA_OBB;
192 break;
193 case PERM_PRE_ROOT:
194 default:
195 break;
Daniel Rosenbergb7c13d82017-01-25 13:48:45 -0800196 }
197 switch (perm) {
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700198 case PERM_ROOT:
199 case PERM_ANDROID:
200 case PERM_ANDROID_DATA:
201 case PERM_ANDROID_MEDIA:
202 if (S_ISDIR(dentry->d_inode->i_mode))
203 gid = multiuser_get_uid(info->userid, AID_MEDIA_RW);
204 else
205 gid = multiuser_get_uid(info->userid, get_type(name));
206 break;
207 case PERM_ANDROID_OBB:
208 gid = AID_MEDIA_OBB;
209 break;
210 case PERM_ANDROID_PACKAGE:
211 if (info->d_uid != 0)
212 gid = multiuser_get_ext_gid(info->d_uid);
213 else
214 gid = multiuser_get_uid(info->userid, uid);
215 break;
216 case PERM_ANDROID_PACKAGE_CACHE:
217 if (info->d_uid != 0)
218 gid = multiuser_get_cache_gid(info->d_uid);
219 else
220 gid = multiuser_get_uid(info->userid, uid);
221 break;
222 case PERM_PRE_ROOT:
223 default:
224 break;
Daniel Rosenbergb7c13d82017-01-25 13:48:45 -0800225 }
226
227 sdcardfs_get_lower_path(dentry, &path);
228 inode = path.dentry->d_inode;
229 if (path.dentry->d_inode->i_gid != gid || path.dentry->d_inode->i_uid != uid) {
230 newattrs.ia_valid = ATTR_GID | ATTR_UID | ATTR_FORCE;
231 newattrs.ia_uid = uid;
232 newattrs.ia_gid = gid;
233 if (!S_ISDIR(inode->i_mode))
234 newattrs.ia_valid |=
235 ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV;
236 mutex_lock(&inode->i_mutex);
237 error = security_path_chown(&path, newattrs.ia_uid, newattrs.ia_gid);
238 if (!error)
239 error = notify_change2(path.mnt, path.dentry, &newattrs);
240 mutex_unlock(&inode->i_mutex);
241 if (error)
242 pr_err("sdcardfs: Failed to touch up lower fs gid/uid.\n");
243 }
Daniel Rosenberg693a9122017-02-16 17:55:22 -0800244 sdcardfs_put_lower_path(dentry, &path);
Daniel Rosenberg5c09ef42016-02-03 21:08:21 -0800245}
246
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700247static int descendant_may_need_fixup(struct sdcardfs_inode_info *info, struct limit_search *limit)
248{
Daniel Rosenberg6a7ea012017-01-22 15:32:49 -0800249 if (info->perm == PERM_ROOT)
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700250 return (limit->flags & BY_USERID) ? info->userid == limit->userid : 1;
Daniel Rosenberg6a7ea012017-01-22 15:32:49 -0800251 if (info->perm == PERM_PRE_ROOT || info->perm == PERM_ANDROID)
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700252 return 1;
253 return 0;
254}
255
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700256static int needs_fixup(perm_t perm)
257{
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700258 if (perm == PERM_ANDROID_DATA || perm == PERM_ANDROID_OBB
259 || perm == PERM_ANDROID_MEDIA)
260 return 1;
261 return 0;
262}
263
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700264static void __fixup_perms_recursive(struct dentry *dentry, struct limit_search *limit, int depth)
265{
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700266 struct dentry *child;
267 struct sdcardfs_inode_info *info;
Daniel Rosenbergf0605742017-03-02 15:11:27 -0800268
269 /*
270 * All paths will terminate their recursion on hitting PERM_ANDROID_OBB,
271 * PERM_ANDROID_MEDIA, or PERM_ANDROID_DATA. This happens at a depth of
272 * at most 3.
273 */
274 WARN(depth > 3, "%s: Max expected depth exceeded!\n", __func__);
275 spin_lock_nested(&dentry->d_lock, depth);
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700276 if (!dentry->d_inode) {
Daniel Rosenbergf0605742017-03-02 15:11:27 -0800277 spin_unlock(&dentry->d_lock);
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700278 return;
279 }
280 info = SDCARDFS_I(dentry->d_inode);
281
282 if (needs_fixup(info->perm)) {
Daniel Rosenberg6d990542016-12-27 12:36:29 -0800283 list_for_each_entry(child, &dentry->d_subdirs, d_child) {
Daniel Rosenbergf0605742017-03-02 15:11:27 -0800284 spin_lock_nested(&child->d_lock, depth + 1);
Daniel Rosenberg47b534f2017-03-08 17:20:02 -0800285 if (!(limit->flags & BY_NAME) || qstr_case_eq(&child->d_name, &limit->name)) {
Daniel Rosenberg6a7ea012017-01-22 15:32:49 -0800286 if (child->d_inode) {
287 get_derived_permission(dentry, child);
288 fixup_tmp_permissions(child->d_inode);
Daniel Rosenbergf0605742017-03-02 15:11:27 -0800289 spin_unlock(&child->d_lock);
Daniel Rosenberg6a7ea012017-01-22 15:32:49 -0800290 break;
Daniel Rosenberg6d990542016-12-27 12:36:29 -0800291 }
Daniel Rosenberg6a7ea012017-01-22 15:32:49 -0800292 }
Daniel Rosenbergf0605742017-03-02 15:11:27 -0800293 spin_unlock(&child->d_lock);
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700294 }
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700295 } else if (descendant_may_need_fixup(info, limit)) {
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700296 list_for_each_entry(child, &dentry->d_subdirs, d_child) {
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700297 __fixup_perms_recursive(child, limit, depth + 1);
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700298 }
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700299 }
Daniel Rosenbergf0605742017-03-02 15:11:27 -0800300 spin_unlock(&dentry->d_lock);
301}
302
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700303void fixup_perms_recursive(struct dentry *dentry, struct limit_search *limit)
304{
Daniel Rosenbergf0605742017-03-02 15:11:27 -0800305 __fixup_perms_recursive(dentry, limit, 0);
Daniel Rosenberg3286c8a2016-05-18 16:57:10 -0700306}
307
Daniel Campello3a703812015-07-20 16:23:50 -0700308/* main function for updating derived permission */
Daniel Rosenberg5c09ef42016-02-03 21:08:21 -0800309inline void update_derived_permission_lock(struct dentry *dentry)
Daniel Campello3a703812015-07-20 16:23:50 -0700310{
311 struct dentry *parent;
312
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700313 if (!dentry || !dentry->d_inode) {
Daniel Campello3a703812015-07-20 16:23:50 -0700314 printk(KERN_ERR "sdcardfs: %s: invalid dentry\n", __func__);
315 return;
316 }
317 /* FIXME:
318 * 1. need to check whether the dentry is updated or not
319 * 2. remove the root dentry update
320 */
Daniel Rosenberg0eacfdd2017-03-16 19:33:35 -0700321 if (!IS_ROOT(dentry)) {
Daniel Campello3a703812015-07-20 16:23:50 -0700322 parent = dget_parent(dentry);
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700323 if (parent) {
Daniel Campello3a703812015-07-20 16:23:50 -0700324 get_derived_permission(parent, dentry);
325 dput(parent);
326 }
327 }
Daniel Rosenberga95870e2016-10-26 20:27:20 -0700328 fixup_tmp_permissions(dentry->d_inode);
Daniel Campello3a703812015-07-20 16:23:50 -0700329}
330
331int need_graft_path(struct dentry *dentry)
332{
333 int ret = 0;
334 struct dentry *parent = dget_parent(dentry);
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700335 struct sdcardfs_inode_info *parent_info = SDCARDFS_I(parent->d_inode);
Daniel Campello3a703812015-07-20 16:23:50 -0700336 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
Daniel Rosenberg2d336b62017-01-31 20:07:51 -0800337 struct qstr obb = QSTR_LITERAL("obb");
Daniel Campello3a703812015-07-20 16:23:50 -0700338
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700339 if (parent_info->perm == PERM_ANDROID &&
Daniel Rosenberg2d336b62017-01-31 20:07:51 -0800340 qstr_case_eq(&dentry->d_name, &obb)) {
Daniel Campello3a703812015-07-20 16:23:50 -0700341
342 /* /Android/obb is the base obbpath of DERIVED_UNIFIED */
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700343 if (!(sbi->options.multiuser == false
Daniel Campello3a703812015-07-20 16:23:50 -0700344 && parent_info->userid == 0)) {
345 ret = 1;
346 }
347 }
348 dput(parent);
349 return ret;
350}
351
352int is_obbpath_invalid(struct dentry *dent)
353{
354 int ret = 0;
355 struct sdcardfs_dentry_info *di = SDCARDFS_D(dent);
356 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dent->d_sb);
357 char *path_buf, *obbpath_s;
Daniel Rosenbergf60ac802017-03-10 13:54:30 -0800358 int need_put = 0;
359 struct path lower_path;
Daniel Campello3a703812015-07-20 16:23:50 -0700360
361 /* check the base obbpath has been changed.
362 * this routine can check an uninitialized obb dentry as well.
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700363 * regarding the uninitialized obb, refer to the sdcardfs_mkdir()
364 */
Daniel Campello3a703812015-07-20 16:23:50 -0700365 spin_lock(&di->lock);
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700366 if (di->orig_path.dentry) {
367 if (!di->lower_path.dentry) {
Daniel Campello3a703812015-07-20 16:23:50 -0700368 ret = 1;
369 } else {
370 path_get(&di->lower_path);
Daniel Campello3a703812015-07-20 16:23:50 -0700371
372 path_buf = kmalloc(PATH_MAX, GFP_ATOMIC);
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700373 if (!path_buf) {
Daniel Campello3a703812015-07-20 16:23:50 -0700374 ret = 1;
Daniel Rosenberg5c09ef42016-02-03 21:08:21 -0800375 printk(KERN_ERR "sdcardfs: fail to allocate path_buf in %s.\n", __func__);
Daniel Campello3a703812015-07-20 16:23:50 -0700376 } else {
377 obbpath_s = d_path(&di->lower_path, path_buf, PATH_MAX);
378 if (d_unhashed(di->lower_path.dentry) ||
Daniel Rosenberg2d336b62017-01-31 20:07:51 -0800379 !str_case_eq(sbi->obbpath_s, obbpath_s)) {
Daniel Campello3a703812015-07-20 16:23:50 -0700380 ret = 1;
381 }
382 kfree(path_buf);
383 }
384
Daniel Rosenbergf60ac802017-03-10 13:54:30 -0800385 pathcpy(&lower_path, &di->lower_path);
386 need_put = 1;
Daniel Campello3a703812015-07-20 16:23:50 -0700387 }
388 }
389 spin_unlock(&di->lock);
Daniel Rosenbergf60ac802017-03-10 13:54:30 -0800390 if (need_put)
391 path_put(&lower_path);
Daniel Campello3a703812015-07-20 16:23:50 -0700392 return ret;
393}
394
395int is_base_obbpath(struct dentry *dentry)
396{
397 int ret = 0;
398 struct dentry *parent = dget_parent(dentry);
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700399 struct sdcardfs_inode_info *parent_info = SDCARDFS_I(parent->d_inode);
Daniel Campello3a703812015-07-20 16:23:50 -0700400 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
Daniel Rosenberg2d336b62017-01-31 20:07:51 -0800401 struct qstr q_obb = QSTR_LITERAL("obb");
Daniel Campello3a703812015-07-20 16:23:50 -0700402
403 spin_lock(&SDCARDFS_D(dentry)->lock);
Daniel Rosenberg5c09ef42016-02-03 21:08:21 -0800404 if (sbi->options.multiuser) {
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700405 if (parent_info->perm == PERM_PRE_ROOT &&
Daniel Rosenberg2d336b62017-01-31 20:07:51 -0800406 qstr_case_eq(&dentry->d_name, &q_obb)) {
Daniel Rosenberg5c09ef42016-02-03 21:08:21 -0800407 ret = 1;
408 }
409 } else if (parent_info->perm == PERM_ANDROID &&
Daniel Rosenberg2d336b62017-01-31 20:07:51 -0800410 qstr_case_eq(&dentry->d_name, &q_obb)) {
Daniel Campello3a703812015-07-20 16:23:50 -0700411 ret = 1;
412 }
Daniel Campello3a703812015-07-20 16:23:50 -0700413 spin_unlock(&SDCARDFS_D(dentry)->lock);
Daniel Campello3a703812015-07-20 16:23:50 -0700414 return ret;
415}
416
417/* The lower_path will be stored to the dentry's orig_path
418 * and the base obbpath will be copyed to the lower_path variable.
419 * if an error returned, there's no change in the lower_path
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700420 * returns: -ERRNO if error (0: no error)
421 */
Daniel Campello3a703812015-07-20 16:23:50 -0700422int setup_obb_dentry(struct dentry *dentry, struct path *lower_path)
423{
424 int err = 0;
425 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
426 struct path obbpath;
427
428 /* A local obb dentry must have its own orig_path to support rmdir
429 * and mkdir of itself. Usually, we expect that the sbi->obbpath
Daniel Rosenberg0eacfdd2017-03-16 19:33:35 -0700430 * is avaiable on this stage.
431 */
Daniel Campello3a703812015-07-20 16:23:50 -0700432 sdcardfs_set_orig_path(dentry, lower_path);
433
434 err = kern_path(sbi->obbpath_s,
435 LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &obbpath);
436
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700437 if (!err) {
Daniel Campello3a703812015-07-20 16:23:50 -0700438 /* the obbpath base has been found */
Daniel Campello3a703812015-07-20 16:23:50 -0700439 pathcpy(lower_path, &obbpath);
440 } else {
441 /* if the sbi->obbpath is not available, we can optionally
442 * setup the lower_path with its orig_path.
443 * but, the current implementation just returns an error
444 * because the sdcard daemon also regards this case as
Daniel Rosenbergbeb00302017-03-16 17:42:58 -0700445 * a lookup fail.
446 */
Daniel Rosenberg5c09ef42016-02-03 21:08:21 -0800447 printk(KERN_INFO "sdcardfs: the sbi->obbpath is not available\n");
Daniel Campello3a703812015-07-20 16:23:50 -0700448 }
449 return err;
450}
451
452