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.
23 /* Do not directly use this function. Use OVERRIDE_CRED() instead. */
24 const struct cred * override_fsids(struct sdcardfs_sb_info* sbi)
27 const struct cred * old_cred;
29 cred = prepare_creds();
33 cred->fsuid = make_kuid(&init_user_ns, sbi->options.fs_low_uid);
34 cred->fsgid = make_kgid(&init_user_ns, sbi->options.fs_low_gid);
36 old_cred = override_creds(cred);
41 /* Do not directly use this function, use REVERT_CRED() instead. */
42 void revert_fsids(const struct cred * old_cred)
44 const struct cred * cur_cred;
46 cur_cred = current->cred;
47 revert_creds(old_cred);
51 static int sdcardfs_create(struct inode *dir, struct dentry *dentry,
52 umode_t mode, bool want_excl)
55 struct dentry *lower_dentry;
56 struct dentry *lower_parent_dentry = NULL;
57 struct path lower_path;
58 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
59 const struct cred *saved_cred = NULL;
61 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
62 if(!check_caller_access_to_name(dir, dentry->d_name.name, sbi->options.derive, 1, has_rw)) {
63 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
64 " dentry: %s, task:%s\n",
65 __func__, dentry->d_name.name, current->comm);
70 /* save current_cred and override it */
71 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred);
73 sdcardfs_get_lower_path(dentry, &lower_path);
74 lower_dentry = lower_path.dentry;
75 lower_parent_dentry = lock_parent(lower_dentry);
77 /* set last 16bytes of mode field to 0664 */
78 mode = (mode & S_IFMT) | 00664;
79 err = vfs_create(d_inode(lower_parent_dentry), lower_dentry, mode, want_excl);
83 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
86 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
87 fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry));
90 unlock_dir(lower_parent_dentry);
91 sdcardfs_put_lower_path(dentry, &lower_path);
92 REVERT_CRED(saved_cred);
98 static int sdcardfs_link(struct dentry *old_dentry, struct inode *dir,
99 struct dentry *new_dentry)
101 struct dentry *lower_old_dentry;
102 struct dentry *lower_new_dentry;
103 struct dentry *lower_dir_dentry;
106 struct path lower_old_path, lower_new_path;
108 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb));
110 file_size_save = i_size_read(d_inode(old_dentry));
111 sdcardfs_get_lower_path(old_dentry, &lower_old_path);
112 sdcardfs_get_lower_path(new_dentry, &lower_new_path);
113 lower_old_dentry = lower_old_path.dentry;
114 lower_new_dentry = lower_new_path.dentry;
115 lower_dir_dentry = lock_parent(lower_new_dentry);
117 err = vfs_link(lower_old_dentry, d_inode(lower_dir_dentry),
118 lower_new_dentry, NULL);
119 if (err || !d_inode(lower_new_dentry))
122 err = sdcardfs_interpose(new_dentry, dir->i_sb, &lower_new_path);
125 fsstack_copy_attr_times(dir, d_inode(lower_new_dentry));
126 fsstack_copy_inode_size(dir, d_inode(lower_new_dentry));
127 set_nlink(d_inode(old_dentry),
128 sdcardfs_lower_inode(d_inode(old_dentry))->i_nlink);
129 i_size_write(d_inode(new_dentry), file_size_save);
131 unlock_dir(lower_dir_dentry);
132 sdcardfs_put_lower_path(old_dentry, &lower_old_path);
133 sdcardfs_put_lower_path(new_dentry, &lower_new_path);
139 static int sdcardfs_unlink(struct inode *dir, struct dentry *dentry)
142 struct dentry *lower_dentry;
143 struct inode *lower_dir_inode = sdcardfs_lower_inode(dir);
144 struct dentry *lower_dir_dentry;
145 struct path lower_path;
146 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
147 const struct cred *saved_cred = NULL;
149 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
150 if(!check_caller_access_to_name(dir, dentry->d_name.name, sbi->options.derive, 1, has_rw)) {
151 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
152 " dentry: %s, task:%s\n",
153 __func__, dentry->d_name.name, current->comm);
158 /* save current_cred and override it */
159 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred);
161 sdcardfs_get_lower_path(dentry, &lower_path);
162 lower_dentry = lower_path.dentry;
164 lower_dir_dentry = lock_parent(lower_dentry);
166 err = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
169 * Note: unlinking on top of NFS can cause silly-renamed files.
170 * Trying to delete such files results in EBUSY from NFS
171 * below. Silly-renamed files will get deleted by NFS later on, so
172 * we just need to detect them here and treat such EBUSY errors as
173 * if the upper file was successfully deleted.
175 if (err == -EBUSY && lower_dentry->d_flags & DCACHE_NFSFS_RENAMED)
179 fsstack_copy_attr_times(dir, lower_dir_inode);
180 fsstack_copy_inode_size(dir, lower_dir_inode);
181 set_nlink(d_inode(dentry),
182 sdcardfs_lower_inode(d_inode(dentry))->i_nlink);
183 d_inode(dentry)->i_ctime = dir->i_ctime;
184 d_drop(dentry); /* this is needed, else LTP fails (VFS won't do it) */
186 unlock_dir(lower_dir_dentry);
188 sdcardfs_put_lower_path(dentry, &lower_path);
189 REVERT_CRED(saved_cred);
195 static int sdcardfs_symlink(struct inode *dir, struct dentry *dentry,
199 struct dentry *lower_dentry;
200 struct dentry *lower_parent_dentry = NULL;
201 struct path lower_path;
203 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb));
205 sdcardfs_get_lower_path(dentry, &lower_path);
206 lower_dentry = lower_path.dentry;
207 lower_parent_dentry = lock_parent(lower_dentry);
209 err = vfs_symlink(d_inode(lower_parent_dentry), lower_dentry, symname);
212 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
215 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
216 fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry));
219 unlock_dir(lower_parent_dentry);
220 sdcardfs_put_lower_path(dentry, &lower_path);
226 static int touch(char *abs_path, mode_t mode) {
227 struct file *filp = filp_open(abs_path, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, mode);
229 if (PTR_ERR(filp) == -EEXIST) {
233 printk(KERN_ERR "sdcardfs: failed to open(%s): %ld\n",
234 abs_path, PTR_ERR(filp));
235 return PTR_ERR(filp);
238 filp_close(filp, current->files);
242 static int sdcardfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
245 int make_nomedia_in_obb = 0;
246 struct dentry *lower_dentry;
247 struct dentry *lower_parent_dentry = NULL;
248 struct path lower_path;
249 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
250 const struct cred *saved_cred = NULL;
251 struct sdcardfs_inode_info *pi = SDCARDFS_I(dir);
253 char *nomedia_dir_name;
254 char *nomedia_fullpath;
255 int fullpath_namelen;
258 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
259 if(!check_caller_access_to_name(dir, dentry->d_name.name, sbi->options.derive, 1, has_rw)) {
260 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
261 " dentry: %s, task:%s\n",
262 __func__, dentry->d_name.name, current->comm);
267 /* save current_cred and override it */
268 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred);
270 /* check disk space */
271 if (!check_min_free_space(dentry, 0, 1)) {
272 printk(KERN_INFO "sdcardfs: No minimum free space.\n");
277 /* the lower_dentry is negative here */
278 sdcardfs_get_lower_path(dentry, &lower_path);
279 lower_dentry = lower_path.dentry;
280 lower_parent_dentry = lock_parent(lower_dentry);
282 /* set last 16bytes of mode field to 0775 */
283 mode = (mode & S_IFMT) | 00775;
284 err = vfs_mkdir(d_inode(lower_parent_dentry), lower_dentry, mode);
289 /* if it is a local obb dentry, setup it with the base obbpath */
290 if(need_graft_path(dentry)) {
292 err = setup_obb_dentry(dentry, &lower_path);
294 /* if the sbi->obbpath is not available, the lower_path won't be
295 * changed by setup_obb_dentry() but the lower path is saved to
296 * its orig_path. this dentry will be revalidated later.
297 * but now, the lower_path should be NULL */
298 sdcardfs_put_reset_lower_path(dentry);
300 /* the newly created lower path which saved to its orig_path or
301 * the lower_path is the base obbpath.
302 * therefore, an additional path_get is required */
303 path_get(&lower_path);
305 make_nomedia_in_obb = 1;
308 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
312 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
313 fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry));
314 /* update number of links on parent directory */
315 set_nlink(dir, sdcardfs_lower_inode(dir)->i_nlink);
317 if ((sbi->options.derive == DERIVE_UNIFIED) && (!strcasecmp(dentry->d_name.name, "obb"))
318 && (pi->perm == PERM_ANDROID) && (pi->userid == 0))
319 make_nomedia_in_obb = 1;
321 /* When creating /Android/data and /Android/obb, mark them as .nomedia */
322 if (make_nomedia_in_obb ||
323 ((pi->perm == PERM_ANDROID) && (!strcasecmp(dentry->d_name.name, "data")))) {
325 page_buf = (char *)__get_free_page(GFP_KERNEL);
327 printk(KERN_ERR "sdcardfs: failed to allocate page buf\n");
331 nomedia_dir_name = d_absolute_path(&lower_path, page_buf, PAGE_SIZE);
332 if (IS_ERR(nomedia_dir_name)) {
333 free_page((unsigned long)page_buf);
334 printk(KERN_ERR "sdcardfs: failed to get .nomedia dir name\n");
338 fullpath_namelen = page_buf + PAGE_SIZE - nomedia_dir_name - 1;
339 fullpath_namelen += strlen("/.nomedia");
340 nomedia_fullpath = kzalloc(fullpath_namelen + 1, GFP_KERNEL);
341 if (!nomedia_fullpath) {
342 free_page((unsigned long)page_buf);
343 printk(KERN_ERR "sdcardfs: failed to allocate .nomedia fullpath buf\n");
347 strcpy(nomedia_fullpath, nomedia_dir_name);
348 free_page((unsigned long)page_buf);
349 strcat(nomedia_fullpath, "/.nomedia");
350 touch_err = touch(nomedia_fullpath, 0664);
352 printk(KERN_ERR "sdcardfs: failed to touch(%s): %d\n",
353 nomedia_fullpath, touch_err);
354 kfree(nomedia_fullpath);
357 kfree(nomedia_fullpath);
360 unlock_dir(lower_parent_dentry);
361 sdcardfs_put_lower_path(dentry, &lower_path);
363 REVERT_CRED(saved_cred);
368 static int sdcardfs_rmdir(struct inode *dir, struct dentry *dentry)
370 struct dentry *lower_dentry;
371 struct dentry *lower_dir_dentry;
373 struct path lower_path;
374 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
375 const struct cred *saved_cred = NULL;
376 //char *path_s = NULL;
378 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
379 if(!check_caller_access_to_name(dir, dentry->d_name.name, sbi->options.derive, 1, has_rw)) {
380 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
381 " dentry: %s, task:%s\n",
382 __func__, dentry->d_name.name, current->comm);
387 /* save current_cred and override it */
388 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred);
390 /* sdcardfs_get_real_lower(): in case of remove an user's obb dentry
391 * the dentry on the original path should be deleted. */
392 sdcardfs_get_real_lower(dentry, &lower_path);
394 lower_dentry = lower_path.dentry;
395 lower_dir_dentry = lock_parent(lower_dentry);
397 err = vfs_rmdir(d_inode(lower_dir_dentry), lower_dentry);
401 d_drop(dentry); /* drop our dentry on success (why not VFS's job?) */
403 clear_nlink(d_inode(dentry));
404 fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
405 fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
406 set_nlink(dir, d_inode(lower_dir_dentry)->i_nlink);
409 unlock_dir(lower_dir_dentry);
410 sdcardfs_put_real_lower(dentry, &lower_path);
411 REVERT_CRED(saved_cred);
417 static int sdcardfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
421 struct dentry *lower_dentry;
422 struct dentry *lower_parent_dentry = NULL;
423 struct path lower_path;
425 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb));
427 sdcardfs_get_lower_path(dentry, &lower_path);
428 lower_dentry = lower_path.dentry;
429 lower_parent_dentry = lock_parent(lower_dentry);
431 err = vfs_mknod(d_inode(lower_parent_dentry), lower_dentry, mode, dev);
435 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
438 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
439 fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry));
442 unlock_dir(lower_parent_dentry);
443 sdcardfs_put_lower_path(dentry, &lower_path);
450 * The locking rules in sdcardfs_rename are complex. We could use a simpler
451 * superblock-level name-space lock for renames and copy-ups.
453 static int sdcardfs_rename(struct inode *old_dir, struct dentry *old_dentry,
454 struct inode *new_dir, struct dentry *new_dentry)
457 struct dentry *lower_old_dentry = NULL;
458 struct dentry *lower_new_dentry = NULL;
459 struct dentry *lower_old_dir_dentry = NULL;
460 struct dentry *lower_new_dir_dentry = NULL;
461 struct dentry *trap = NULL;
462 struct dentry *new_parent = NULL;
463 struct path lower_old_path, lower_new_path;
464 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(old_dentry->d_sb);
465 const struct cred *saved_cred = NULL;
467 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
468 if(!check_caller_access_to_name(old_dir, old_dentry->d_name.name,
469 sbi->options.derive, 1, has_rw) ||
470 !check_caller_access_to_name(new_dir, new_dentry->d_name.name,
471 sbi->options.derive, 1, has_rw)) {
472 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
473 " new_dentry: %s, task:%s\n",
474 __func__, new_dentry->d_name.name, current->comm);
479 /* save current_cred and override it */
480 OVERRIDE_CRED(SDCARDFS_SB(old_dir->i_sb), saved_cred);
482 sdcardfs_get_real_lower(old_dentry, &lower_old_path);
483 sdcardfs_get_lower_path(new_dentry, &lower_new_path);
484 lower_old_dentry = lower_old_path.dentry;
485 lower_new_dentry = lower_new_path.dentry;
486 lower_old_dir_dentry = dget_parent(lower_old_dentry);
487 lower_new_dir_dentry = dget_parent(lower_new_dentry);
489 trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
490 /* source should not be ancestor of target */
491 if (trap == lower_old_dentry) {
495 /* target should not be ancestor of source */
496 if (trap == lower_new_dentry) {
501 err = vfs_rename(d_inode(lower_old_dir_dentry), lower_old_dentry,
502 d_inode(lower_new_dir_dentry), lower_new_dentry,
507 /* Copy attrs from lower dir, but i_uid/i_gid */
508 fsstack_copy_attr_all(new_dir, d_inode(lower_new_dir_dentry));
509 fsstack_copy_inode_size(new_dir, d_inode(lower_new_dir_dentry));
510 fix_derived_permission(new_dir);
511 if (new_dir != old_dir) {
512 fsstack_copy_attr_all(old_dir, d_inode(lower_old_dir_dentry));
513 fsstack_copy_inode_size(old_dir, d_inode(lower_old_dir_dentry));
514 fix_derived_permission(old_dir);
515 /* update the derived permission of the old_dentry
516 * with its new parent
518 new_parent = dget_parent(new_dentry);
520 if(d_inode(old_dentry)) {
521 get_derived_permission(new_parent, old_dentry);
522 fix_derived_permission(d_inode(old_dentry));
529 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
530 dput(lower_old_dir_dentry);
531 dput(lower_new_dir_dentry);
532 sdcardfs_put_real_lower(old_dentry, &lower_old_path);
533 sdcardfs_put_lower_path(new_dentry, &lower_new_path);
534 REVERT_CRED(saved_cred);
540 static int sdcardfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
543 struct dentry *lower_dentry;
544 struct path lower_path;
545 /* XXX readlink does not requires overriding credential */
547 sdcardfs_get_lower_path(dentry, &lower_path);
548 lower_dentry = lower_path.dentry;
549 if (!d_inode(lower_dentry)->i_op ||
550 !d_inode(lower_dentry)->i_op->readlink) {
555 err = d_inode(lower_dentry)->i_op->readlink(lower_dentry,
559 fsstack_copy_attr_atime(d_inode(dentry), d_inode(lower_dentry));
562 sdcardfs_put_lower_path(dentry, &lower_path);
568 static const char *sdcardfs_follow_link(struct dentry *dentry, void **cookie)
571 int len = PAGE_SIZE, err;
574 /* This is freed by the put_link method assuming a successful call. */
575 buf = kmalloc(len, GFP_KERNEL);
577 buf = ERR_PTR(-ENOMEM);
581 /* read the symlink, and then we will follow it */
584 err = sdcardfs_readlink(dentry, buf, len);
592 return *cookie = buf;
596 static int sdcardfs_permission(struct inode *inode, int mask)
601 * Permission check on sdcardfs inode.
602 * Calling process should have AID_SDCARD_RW permission
604 err = generic_permission(inode, mask);
607 * Original sdcardfs code calls inode_permission(lower_inode,.. )
608 * for checking inode permission. But doing such things here seems
609 * duplicated work, because the functions called after this func,
610 * such as vfs_create, vfs_unlink, vfs_rename, and etc,
611 * does exactly same thing, i.e., they calls inode_permission().
612 * So we just let they do the things.
613 * If there are any security hole, just uncomment following if block.
618 * Permission check on lower_inode(=EXT4).
619 * we check it with AID_MEDIA_RW permission
621 struct inode *lower_inode;
622 OVERRIDE_CRED(SDCARDFS_SB(inode->sb));
624 lower_inode = sdcardfs_lower_inode(inode);
625 err = inode_permission(lower_inode, mask);
634 static int sdcardfs_setattr(struct dentry *dentry, struct iattr *ia)
637 struct dentry *lower_dentry;
639 struct inode *lower_inode;
640 struct path lower_path;
641 struct iattr lower_ia;
642 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
643 struct dentry *parent;
646 inode = d_inode(dentry);
649 * Check if user has permission to change inode. We don't check if
650 * this user can change the lower inode: that should happen when
651 * calling notify_change on the lower inode.
653 err = inode_change_ok(inode, ia);
655 /* no vfs_XXX operations required, cred overriding will be skipped. wj*/
657 /* check the Android group ID */
658 has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
659 parent = dget_parent(dentry);
660 if(!check_caller_access_to_name(d_inode(parent), dentry->d_name.name,
661 sbi->options.derive, 1, has_rw)) {
662 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
663 " dentry: %s, task:%s\n",
664 __func__, dentry->d_name.name, current->comm);
673 sdcardfs_get_lower_path(dentry, &lower_path);
674 lower_dentry = lower_path.dentry;
675 lower_inode = sdcardfs_lower_inode(inode);
677 /* prepare our own lower struct iattr (with the lower file) */
678 memcpy(&lower_ia, ia, sizeof(lower_ia));
679 if (ia->ia_valid & ATTR_FILE)
680 lower_ia.ia_file = sdcardfs_lower_file(ia->ia_file);
682 lower_ia.ia_valid &= ~(ATTR_UID | ATTR_GID | ATTR_MODE);
685 * If shrinking, first truncate upper level to cancel writing dirty
686 * pages beyond the new eof; and also if its' maxbytes is more
687 * limiting (fail with -EFBIG before making any change to the lower
688 * level). There is no need to vmtruncate the upper level
689 * afterwards in the other cases: we fsstack_copy_inode_size from
693 down_write(¤t->mm->mmap_sem);
694 if (ia->ia_valid & ATTR_SIZE) {
695 err = inode_newsize_ok(inode, ia->ia_size);
698 up_write(¤t->mm->mmap_sem);
701 truncate_setsize(inode, ia->ia_size);
705 * mode change is for clearing setuid/setgid bits. Allow lower fs
706 * to interpret this in its own way.
708 if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
709 lower_ia.ia_valid &= ~ATTR_MODE;
711 /* notify the (possibly copied-up) lower inode */
713 * Note: we use d_inode(lower_dentry), because lower_inode may be
714 * unlinked (no inode->i_sb and i_ino==0. This happens if someone
715 * tries to open(), unlink(), then ftruncate() a file.
717 mutex_lock(&d_inode(lower_dentry)->i_mutex);
718 err = notify_change(lower_dentry, &lower_ia, /* note: lower_ia */
720 mutex_unlock(&d_inode(lower_dentry)->i_mutex);
722 up_write(¤t->mm->mmap_sem);
726 /* get attributes from the lower inode */
727 fsstack_copy_attr_all(inode, lower_inode);
728 /* update derived permission of the upper inode */
729 fix_derived_permission(inode);
732 * Not running fsstack_copy_inode_size(inode, lower_inode), because
733 * VFS should update our inode size, and notify_change on
734 * lower_inode should update its size.
738 sdcardfs_put_lower_path(dentry, &lower_path);
743 static int sdcardfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
746 struct dentry *lower_dentry;
748 struct inode *lower_inode;
749 struct path lower_path;
750 struct dentry *parent;
751 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
753 parent = dget_parent(dentry);
754 if(!check_caller_access_to_name(d_inode(parent), dentry->d_name.name,
755 sbi->options.derive, 0, 0)) {
756 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
757 " dentry: %s, task:%s\n",
758 __func__, dentry->d_name.name, current->comm);
764 inode = d_inode(dentry);
766 sdcardfs_get_lower_path(dentry, &lower_path);
767 lower_dentry = lower_path.dentry;
768 lower_inode = sdcardfs_lower_inode(inode);
770 fsstack_copy_attr_all(inode, lower_inode);
771 fsstack_copy_inode_size(inode, lower_inode);
772 /* if the dentry has been moved from other location
773 * so, on this stage, its derived permission must be
774 * rechecked from its private field.
776 fix_derived_permission(inode);
778 generic_fillattr(inode, stat);
779 sdcardfs_put_lower_path(dentry, &lower_path);
783 const struct inode_operations sdcardfs_symlink_iops = {
784 .permission = sdcardfs_permission,
785 .setattr = sdcardfs_setattr,
786 /* XXX Following operations are implemented,
787 * but FUSE(sdcard) or FAT does not support them
788 * These methods are *NOT* perfectly tested.
789 .readlink = sdcardfs_readlink,
790 .follow_link = sdcardfs_follow_link,
791 .put_link = kfree_put_link,
795 const struct inode_operations sdcardfs_dir_iops = {
796 .create = sdcardfs_create,
797 .lookup = sdcardfs_lookup,
799 .permission = sdcardfs_permission,
801 .unlink = sdcardfs_unlink,
802 .mkdir = sdcardfs_mkdir,
803 .rmdir = sdcardfs_rmdir,
804 .rename = sdcardfs_rename,
805 .setattr = sdcardfs_setattr,
806 .getattr = sdcardfs_getattr,
807 /* XXX Following operations are implemented,
808 * but FUSE(sdcard) or FAT does not support them
809 * These methods are *NOT* perfectly tested.
810 .symlink = sdcardfs_symlink,
811 .link = sdcardfs_link,
812 .mknod = sdcardfs_mknod,
816 const struct inode_operations sdcardfs_main_iops = {
817 .permission = sdcardfs_permission,
818 .setattr = sdcardfs_setattr,
819 .getattr = sdcardfs_getattr,