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/fs_struct.h>
24 /* Do not directly use this function. Use OVERRIDE_CRED() instead. */
25 const struct cred * override_fsids(struct sdcardfs_sb_info* sbi, struct sdcardfs_inode_info *info)
28 const struct cred * old_cred;
31 cred = prepare_creds();
38 uid = multiuser_get_uid(info->userid, sbi->options.fs_low_uid);
39 cred->fsuid = make_kuid(&init_user_ns, uid);
40 cred->fsgid = make_kgid(&init_user_ns, sbi->options.fs_low_gid);
42 old_cred = override_creds(cred);
47 /* Do not directly use this function, use REVERT_CRED() instead. */
48 void revert_fsids(const struct cred * old_cred)
50 const struct cred * cur_cred;
52 cur_cred = current->cred;
53 revert_creds(old_cred);
57 static int sdcardfs_create(struct inode *dir, struct dentry *dentry,
58 umode_t mode, bool want_excl)
61 struct dentry *lower_dentry;
62 struct vfsmount *lower_dentry_mnt;
63 struct dentry *lower_parent_dentry = NULL;
64 struct path lower_path;
65 const struct cred *saved_cred = NULL;
66 struct fs_struct *saved_fs;
67 struct fs_struct *copied_fs;
69 if(!check_caller_access_to_name(dir, dentry->d_name.name)) {
70 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
71 " dentry: %s, task:%s\n",
72 __func__, dentry->d_name.name, current->comm);
77 /* save current_cred and override it */
78 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(dir));
80 sdcardfs_get_lower_path(dentry, &lower_path);
81 lower_dentry = lower_path.dentry;
82 lower_dentry_mnt = lower_path.mnt;
83 lower_parent_dentry = lock_parent(lower_dentry);
85 /* set last 16bytes of mode field to 0664 */
86 mode = (mode & S_IFMT) | 00664;
88 /* temporarily change umask for lower fs write */
89 saved_fs = current->fs;
90 copied_fs = copy_fs_struct(current->fs);
95 current->fs = copied_fs;
96 current->fs->umask = 0;
97 err = vfs_create2(lower_dentry_mnt, d_inode(lower_parent_dentry), lower_dentry, mode, want_excl);
101 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path, SDCARDFS_I(dir)->userid);
104 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
105 fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry));
106 fixup_lower_ownership(dentry, dentry->d_name.name);
109 current->fs = saved_fs;
110 free_fs_struct(copied_fs);
112 unlock_dir(lower_parent_dentry);
113 sdcardfs_put_lower_path(dentry, &lower_path);
114 REVERT_CRED(saved_cred);
120 static int sdcardfs_link(struct dentry *old_dentry, struct inode *dir,
121 struct dentry *new_dentry)
123 struct dentry *lower_old_dentry;
124 struct dentry *lower_new_dentry;
125 struct dentry *lower_dir_dentry;
128 struct path lower_old_path, lower_new_path;
130 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb));
132 file_size_save = i_size_read(d_inode(old_dentry));
133 sdcardfs_get_lower_path(old_dentry, &lower_old_path);
134 sdcardfs_get_lower_path(new_dentry, &lower_new_path);
135 lower_old_dentry = lower_old_path.dentry;
136 lower_new_dentry = lower_new_path.dentry;
137 lower_dir_dentry = lock_parent(lower_new_dentry);
139 err = vfs_link(lower_old_dentry, d_inode(lower_dir_dentry),
140 lower_new_dentry, NULL);
141 if (err || !d_inode(lower_new_dentry))
144 err = sdcardfs_interpose(new_dentry, dir->i_sb, &lower_new_path);
147 fsstack_copy_attr_times(dir, d_inode(lower_new_dentry));
148 fsstack_copy_inode_size(dir, d_inode(lower_new_dentry));
149 set_nlink(d_inode(old_dentry),
150 sdcardfs_lower_inode(d_inode(old_dentry))->i_nlink);
151 i_size_write(d_inode(new_dentry), file_size_save);
153 unlock_dir(lower_dir_dentry);
154 sdcardfs_put_lower_path(old_dentry, &lower_old_path);
155 sdcardfs_put_lower_path(new_dentry, &lower_new_path);
161 static int sdcardfs_unlink(struct inode *dir, struct dentry *dentry)
164 struct dentry *lower_dentry;
165 struct vfsmount *lower_mnt;
166 struct inode *lower_dir_inode = sdcardfs_lower_inode(dir);
167 struct dentry *lower_dir_dentry;
168 struct path lower_path;
169 const struct cred *saved_cred = NULL;
171 if(!check_caller_access_to_name(dir, dentry->d_name.name)) {
172 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
173 " dentry: %s, task:%s\n",
174 __func__, dentry->d_name.name, current->comm);
179 /* save current_cred and override it */
180 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(dir));
182 sdcardfs_get_lower_path(dentry, &lower_path);
183 lower_dentry = lower_path.dentry;
184 lower_mnt = lower_path.mnt;
186 lower_dir_dentry = lock_parent(lower_dentry);
188 err = vfs_unlink2(lower_mnt, lower_dir_inode, lower_dentry, NULL);
191 * Note: unlinking on top of NFS can cause silly-renamed files.
192 * Trying to delete such files results in EBUSY from NFS
193 * below. Silly-renamed files will get deleted by NFS later on, so
194 * we just need to detect them here and treat such EBUSY errors as
195 * if the upper file was successfully deleted.
197 if (err == -EBUSY && lower_dentry->d_flags & DCACHE_NFSFS_RENAMED)
201 fsstack_copy_attr_times(dir, lower_dir_inode);
202 fsstack_copy_inode_size(dir, lower_dir_inode);
203 set_nlink(d_inode(dentry),
204 sdcardfs_lower_inode(d_inode(dentry))->i_nlink);
205 d_inode(dentry)->i_ctime = dir->i_ctime;
206 d_drop(dentry); /* this is needed, else LTP fails (VFS won't do it) */
208 unlock_dir(lower_dir_dentry);
210 sdcardfs_put_lower_path(dentry, &lower_path);
211 REVERT_CRED(saved_cred);
217 static int sdcardfs_symlink(struct inode *dir, struct dentry *dentry,
221 struct dentry *lower_dentry;
222 struct dentry *lower_parent_dentry = NULL;
223 struct path lower_path;
225 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb));
227 sdcardfs_get_lower_path(dentry, &lower_path);
228 lower_dentry = lower_path.dentry;
229 lower_parent_dentry = lock_parent(lower_dentry);
231 err = vfs_symlink(d_inode(lower_parent_dentry), lower_dentry, symname);
234 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
237 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
238 fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry));
241 unlock_dir(lower_parent_dentry);
242 sdcardfs_put_lower_path(dentry, &lower_path);
248 static int touch(char *abs_path, mode_t mode) {
249 struct file *filp = filp_open(abs_path, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, mode);
251 if (PTR_ERR(filp) == -EEXIST) {
255 printk(KERN_ERR "sdcardfs: failed to open(%s): %ld\n",
256 abs_path, PTR_ERR(filp));
257 return PTR_ERR(filp);
260 filp_close(filp, current->files);
264 static int sdcardfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
267 int make_nomedia_in_obb = 0;
268 struct dentry *lower_dentry;
269 struct vfsmount *lower_mnt;
270 struct dentry *lower_parent_dentry = NULL;
271 struct path lower_path;
272 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
273 const struct cred *saved_cred = NULL;
274 struct sdcardfs_inode_info *pi = SDCARDFS_I(dir);
276 struct fs_struct *saved_fs;
277 struct fs_struct *copied_fs;
279 if(!check_caller_access_to_name(dir, dentry->d_name.name)) {
280 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
281 " dentry: %s, task:%s\n",
282 __func__, dentry->d_name.name, current->comm);
287 /* save current_cred and override it */
288 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(dir));
290 /* check disk space */
291 if (!check_min_free_space(dentry, 0, 1)) {
292 printk(KERN_INFO "sdcardfs: No minimum free space.\n");
297 /* the lower_dentry is negative here */
298 sdcardfs_get_lower_path(dentry, &lower_path);
299 lower_dentry = lower_path.dentry;
300 lower_mnt = lower_path.mnt;
301 lower_parent_dentry = lock_parent(lower_dentry);
303 /* set last 16bytes of mode field to 0775 */
304 mode = (mode & S_IFMT) | 00775;
306 /* temporarily change umask for lower fs write */
307 saved_fs = current->fs;
308 copied_fs = copy_fs_struct(current->fs);
311 unlock_dir(lower_parent_dentry);
314 current->fs = copied_fs;
315 current->fs->umask = 0;
316 err = vfs_mkdir2(lower_mnt, d_inode(lower_parent_dentry), lower_dentry, mode);
319 unlock_dir(lower_parent_dentry);
323 /* if it is a local obb dentry, setup it with the base obbpath */
324 if(need_graft_path(dentry)) {
326 err = setup_obb_dentry(dentry, &lower_path);
328 /* if the sbi->obbpath is not available, the lower_path won't be
329 * changed by setup_obb_dentry() but the lower path is saved to
330 * its orig_path. this dentry will be revalidated later.
331 * but now, the lower_path should be NULL */
332 sdcardfs_put_reset_lower_path(dentry);
334 /* the newly created lower path which saved to its orig_path or
335 * the lower_path is the base obbpath.
336 * therefore, an additional path_get is required */
337 path_get(&lower_path);
339 make_nomedia_in_obb = 1;
342 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path, pi->userid);
344 unlock_dir(lower_parent_dentry);
348 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
349 fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry));
350 /* update number of links on parent directory */
351 set_nlink(dir, sdcardfs_lower_inode(dir)->i_nlink);
352 fixup_lower_ownership(dentry, dentry->d_name.name);
353 unlock_dir(lower_parent_dentry);
354 if ((!sbi->options.multiuser) && (!strcasecmp(dentry->d_name.name, "obb"))
355 && (pi->perm == PERM_ANDROID) && (pi->userid == 0))
356 make_nomedia_in_obb = 1;
358 /* When creating /Android/data and /Android/obb, mark them as .nomedia */
359 if (make_nomedia_in_obb ||
360 ((pi->perm == PERM_ANDROID) && (!strcasecmp(dentry->d_name.name, "data")))) {
361 REVERT_CRED(saved_cred);
362 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(d_inode(dentry)));
363 set_fs_pwd(current->fs, &lower_path);
364 touch_err = touch(".nomedia", 0664);
366 printk(KERN_ERR "sdcardfs: failed to create .nomedia in %s: %d\n",
367 lower_path.dentry->d_name.name, touch_err);
372 current->fs = saved_fs;
373 free_fs_struct(copied_fs);
375 sdcardfs_put_lower_path(dentry, &lower_path);
377 REVERT_CRED(saved_cred);
382 static int sdcardfs_rmdir(struct inode *dir, struct dentry *dentry)
384 struct dentry *lower_dentry;
385 struct dentry *lower_dir_dentry;
386 struct vfsmount *lower_mnt;
388 struct path lower_path;
389 const struct cred *saved_cred = NULL;
391 if(!check_caller_access_to_name(dir, dentry->d_name.name)) {
392 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
393 " dentry: %s, task:%s\n",
394 __func__, dentry->d_name.name, current->comm);
399 /* save current_cred and override it */
400 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(dir));
402 /* sdcardfs_get_real_lower(): in case of remove an user's obb dentry
403 * the dentry on the original path should be deleted. */
404 sdcardfs_get_real_lower(dentry, &lower_path);
406 lower_dentry = lower_path.dentry;
407 lower_mnt = lower_path.mnt;
408 lower_dir_dentry = lock_parent(lower_dentry);
410 err = vfs_rmdir2(lower_mnt, d_inode(lower_dir_dentry), lower_dentry);
414 d_drop(dentry); /* drop our dentry on success (why not VFS's job?) */
416 clear_nlink(d_inode(dentry));
417 fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry));
418 fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry));
419 set_nlink(dir, d_inode(lower_dir_dentry)->i_nlink);
422 unlock_dir(lower_dir_dentry);
423 sdcardfs_put_real_lower(dentry, &lower_path);
424 REVERT_CRED(saved_cred);
430 static int sdcardfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
434 struct dentry *lower_dentry;
435 struct dentry *lower_parent_dentry = NULL;
436 struct path lower_path;
438 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb));
440 sdcardfs_get_lower_path(dentry, &lower_path);
441 lower_dentry = lower_path.dentry;
442 lower_parent_dentry = lock_parent(lower_dentry);
444 err = vfs_mknod(d_inode(lower_parent_dentry), lower_dentry, mode, dev);
448 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
451 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
452 fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry));
455 unlock_dir(lower_parent_dentry);
456 sdcardfs_put_lower_path(dentry, &lower_path);
463 * The locking rules in sdcardfs_rename are complex. We could use a simpler
464 * superblock-level name-space lock for renames and copy-ups.
466 static int sdcardfs_rename(struct inode *old_dir, struct dentry *old_dentry,
467 struct inode *new_dir, struct dentry *new_dentry)
470 struct dentry *lower_old_dentry = NULL;
471 struct dentry *lower_new_dentry = NULL;
472 struct dentry *lower_old_dir_dentry = NULL;
473 struct dentry *lower_new_dir_dentry = NULL;
474 struct vfsmount *lower_mnt = NULL;
475 struct dentry *trap = NULL;
476 struct path lower_old_path, lower_new_path;
477 const struct cred *saved_cred = NULL;
479 if(!check_caller_access_to_name(old_dir, old_dentry->d_name.name) ||
480 !check_caller_access_to_name(new_dir, new_dentry->d_name.name)) {
481 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
482 " new_dentry: %s, task:%s\n",
483 __func__, new_dentry->d_name.name, current->comm);
488 /* save current_cred and override it */
489 OVERRIDE_CRED(SDCARDFS_SB(old_dir->i_sb), saved_cred, SDCARDFS_I(new_dir));
491 sdcardfs_get_real_lower(old_dentry, &lower_old_path);
492 sdcardfs_get_lower_path(new_dentry, &lower_new_path);
493 lower_old_dentry = lower_old_path.dentry;
494 lower_new_dentry = lower_new_path.dentry;
495 lower_mnt = lower_old_path.mnt;
496 lower_old_dir_dentry = dget_parent(lower_old_dentry);
497 lower_new_dir_dentry = dget_parent(lower_new_dentry);
499 trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
500 /* source should not be ancestor of target */
501 if (trap == lower_old_dentry) {
505 /* target should not be ancestor of source */
506 if (trap == lower_new_dentry) {
511 err = vfs_rename2(lower_mnt,
512 d_inode(lower_old_dir_dentry), lower_old_dentry,
513 d_inode(lower_new_dir_dentry), lower_new_dentry,
518 /* Copy attrs from lower dir, but i_uid/i_gid */
519 sdcardfs_copy_and_fix_attrs(new_dir, d_inode(lower_new_dir_dentry));
520 fsstack_copy_inode_size(new_dir, d_inode(lower_new_dir_dentry));
522 if (new_dir != old_dir) {
523 sdcardfs_copy_and_fix_attrs(old_dir, d_inode(lower_old_dir_dentry));
524 fsstack_copy_inode_size(old_dir, d_inode(lower_old_dir_dentry));
526 get_derived_permission_new(new_dentry->d_parent, old_dentry, new_dentry->d_name.name);
527 fixup_tmp_permissions(d_inode(old_dentry));
528 fixup_lower_ownership(old_dentry, new_dentry->d_name.name);
529 drop_recursive(old_dentry); /* Can't fixup ownership recursively :( */
531 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
532 dput(lower_old_dir_dentry);
533 dput(lower_new_dir_dentry);
534 sdcardfs_put_real_lower(old_dentry, &lower_old_path);
535 sdcardfs_put_lower_path(new_dentry, &lower_new_path);
536 REVERT_CRED(saved_cred);
542 static int sdcardfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
545 struct dentry *lower_dentry;
546 struct path lower_path;
547 /* XXX readlink does not requires overriding credential */
549 sdcardfs_get_lower_path(dentry, &lower_path);
550 lower_dentry = lower_path.dentry;
551 if (!d_inode(lower_dentry)->i_op ||
552 !d_inode(lower_dentry)->i_op->readlink) {
557 err = d_inode(lower_dentry)->i_op->readlink(lower_dentry,
561 fsstack_copy_attr_atime(d_inode(dentry), d_inode(lower_dentry));
564 sdcardfs_put_lower_path(dentry, &lower_path);
570 static const char *sdcardfs_follow_link(struct dentry *dentry, void **cookie)
573 int len = PAGE_SIZE, err;
576 /* This is freed by the put_link method assuming a successful call. */
577 buf = kmalloc(len, GFP_KERNEL);
579 buf = ERR_PTR(-ENOMEM);
583 /* read the symlink, and then we will follow it */
586 err = sdcardfs_readlink(dentry, buf, len);
594 return *cookie = buf;
598 static int sdcardfs_permission_wrn(struct inode *inode, int mask)
600 WARN(1, "sdcardfs does not support permission. Use permission2.\n");
604 void copy_attrs(struct inode *dest, const struct inode *src)
606 dest->i_mode = src->i_mode;
607 dest->i_uid = src->i_uid;
608 dest->i_gid = src->i_gid;
609 dest->i_rdev = src->i_rdev;
610 dest->i_atime = src->i_atime;
611 dest->i_mtime = src->i_mtime;
612 dest->i_ctime = src->i_ctime;
613 dest->i_blkbits = src->i_blkbits;
614 dest->i_flags = src->i_flags;
615 #ifdef CONFIG_FS_POSIX_ACL
616 dest->i_acl = src->i_acl;
618 #ifdef CONFIG_SECURITY
619 dest->i_security = src->i_security;
623 static int sdcardfs_permission(struct vfsmount *mnt, struct inode *inode, int mask)
627 struct inode *top = grab_top(SDCARDFS_I(inode));
630 release_top(SDCARDFS_I(inode));
631 WARN(1, "Top value was null!\n");
636 * Permission check on sdcardfs inode.
637 * Calling process should have AID_SDCARD_RW permission
638 * Since generic_permission only needs i_mode, i_uid,
639 * i_gid, and i_sb, we can create a fake inode to pass
640 * this information down in.
642 * The underlying code may attempt to take locks in some
643 * cases for features we're not using, but if that changes,
644 * locks must be dealt with to avoid undefined behavior.
646 copy_attrs(&tmp, inode);
647 tmp.i_uid = make_kuid(&init_user_ns, SDCARDFS_I(top)->d_uid);
648 tmp.i_gid = make_kgid(&init_user_ns, get_gid(mnt, SDCARDFS_I(top)));
649 tmp.i_mode = (inode->i_mode & S_IFMT) | get_mode(mnt, SDCARDFS_I(top));
650 release_top(SDCARDFS_I(inode));
651 tmp.i_sb = inode->i_sb;
652 if (IS_POSIXACL(inode))
653 printk(KERN_WARNING "%s: This may be undefined behavior... \n", __func__);
654 err = generic_permission(&tmp, mask);
656 * Original sdcardfs code calls inode_permission(lower_inode,.. )
657 * for checking inode permission. But doing such things here seems
658 * duplicated work, because the functions called after this func,
659 * such as vfs_create, vfs_unlink, vfs_rename, and etc,
660 * does exactly same thing, i.e., they calls inode_permission().
661 * So we just let they do the things.
662 * If there are any security hole, just uncomment following if block.
667 * Permission check on lower_inode(=EXT4).
668 * we check it with AID_MEDIA_RW permission
670 struct inode *lower_inode;
671 OVERRIDE_CRED(SDCARDFS_SB(inode->sb));
673 lower_inode = sdcardfs_lower_inode(inode);
674 err = inode_permission(lower_inode, mask);
683 static int sdcardfs_setattr_wrn(struct dentry *dentry, struct iattr *ia)
685 WARN(1, "sdcardfs does not support setattr. User setattr2.\n");
689 static int sdcardfs_setattr(struct vfsmount *mnt, struct dentry *dentry, struct iattr *ia)
692 struct dentry *lower_dentry;
693 struct vfsmount *lower_mnt;
695 struct inode *lower_inode;
696 struct path lower_path;
697 struct iattr lower_ia;
698 struct dentry *parent;
701 const struct cred *saved_cred = NULL;
703 inode = d_inode(dentry);
704 top = grab_top(SDCARDFS_I(inode));
707 release_top(SDCARDFS_I(inode));
712 * Permission check on sdcardfs inode.
713 * Calling process should have AID_SDCARD_RW permission
714 * Since generic_permission only needs i_mode, i_uid,
715 * i_gid, and i_sb, we can create a fake inode to pass
716 * this information down in.
718 * The underlying code may attempt to take locks in some
719 * cases for features we're not using, but if that changes,
720 * locks must be dealt with to avoid undefined behavior.
723 copy_attrs(&tmp, inode);
724 tmp.i_uid = make_kuid(&init_user_ns, SDCARDFS_I(top)->d_uid);
725 tmp.i_gid = make_kgid(&init_user_ns, get_gid(mnt, SDCARDFS_I(top)));
726 tmp.i_mode = (inode->i_mode & S_IFMT) | get_mode(mnt, SDCARDFS_I(top));
727 tmp.i_size = i_size_read(inode);
728 release_top(SDCARDFS_I(inode));
729 tmp.i_sb = inode->i_sb;
732 * Check if user has permission to change inode. We don't check if
733 * this user can change the lower inode: that should happen when
734 * calling notify_change on the lower inode.
736 /* prepare our own lower struct iattr (with the lower file) */
737 memcpy(&lower_ia, ia, sizeof(lower_ia));
738 /* Allow touch updating timestamps. A previous permission check ensures
739 * we have write access. Changes to mode, owner, and group are ignored*/
740 ia->ia_valid |= ATTR_FORCE;
741 err = inode_change_ok(&tmp, ia);
744 /* check the Android group ID */
745 parent = dget_parent(dentry);
746 if(!check_caller_access_to_name(d_inode(parent), dentry->d_name.name)) {
747 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
748 " dentry: %s, task:%s\n",
749 __func__, dentry->d_name.name, current->comm);
758 /* save current_cred and override it */
759 OVERRIDE_CRED(SDCARDFS_SB(dentry->d_sb), saved_cred, SDCARDFS_I(inode));
761 sdcardfs_get_lower_path(dentry, &lower_path);
762 lower_dentry = lower_path.dentry;
763 lower_mnt = lower_path.mnt;
764 lower_inode = sdcardfs_lower_inode(inode);
766 if (ia->ia_valid & ATTR_FILE)
767 lower_ia.ia_file = sdcardfs_lower_file(ia->ia_file);
769 lower_ia.ia_valid &= ~(ATTR_UID | ATTR_GID | ATTR_MODE);
772 * If shrinking, first truncate upper level to cancel writing dirty
773 * pages beyond the new eof; and also if its' maxbytes is more
774 * limiting (fail with -EFBIG before making any change to the lower
775 * level). There is no need to vmtruncate the upper level
776 * afterwards in the other cases: we fsstack_copy_inode_size from
780 down_write(¤t->mm->mmap_sem);
781 if (ia->ia_valid & ATTR_SIZE) {
782 err = inode_newsize_ok(&tmp, ia->ia_size);
785 up_write(¤t->mm->mmap_sem);
788 truncate_setsize(inode, ia->ia_size);
792 * mode change is for clearing setuid/setgid bits. Allow lower fs
793 * to interpret this in its own way.
795 if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
796 lower_ia.ia_valid &= ~ATTR_MODE;
798 /* notify the (possibly copied-up) lower inode */
800 * Note: we use d_inode(lower_dentry), because lower_inode may be
801 * unlinked (no inode->i_sb and i_ino==0. This happens if someone
802 * tries to open(), unlink(), then ftruncate() a file.
804 mutex_lock(&d_inode(lower_dentry)->i_mutex);
805 err = notify_change2(lower_mnt, lower_dentry, &lower_ia, /* note: lower_ia */
807 mutex_unlock(&d_inode(lower_dentry)->i_mutex);
809 up_write(¤t->mm->mmap_sem);
813 /* get attributes from the lower inode and update derived permissions */
814 sdcardfs_copy_and_fix_attrs(inode, lower_inode);
817 * Not running fsstack_copy_inode_size(inode, lower_inode), because
818 * VFS should update our inode size, and notify_change on
819 * lower_inode should update its size.
823 sdcardfs_put_lower_path(dentry, &lower_path);
824 REVERT_CRED(saved_cred);
829 static int sdcardfs_fillattr(struct vfsmount *mnt, struct inode *inode, struct kstat *stat)
831 struct sdcardfs_inode_info *info = SDCARDFS_I(inode);
832 struct inode *top = grab_top(info);
836 stat->dev = inode->i_sb->s_dev;
837 stat->ino = inode->i_ino;
838 stat->mode = (inode->i_mode & S_IFMT) | get_mode(mnt, SDCARDFS_I(top));
839 stat->nlink = inode->i_nlink;
840 stat->uid = make_kuid(&init_user_ns, SDCARDFS_I(top)->d_uid);
841 stat->gid = make_kgid(&init_user_ns, get_gid(mnt, SDCARDFS_I(top)));
842 stat->rdev = inode->i_rdev;
843 stat->size = i_size_read(inode);
844 stat->atime = inode->i_atime;
845 stat->mtime = inode->i_mtime;
846 stat->ctime = inode->i_ctime;
847 stat->blksize = (1 << inode->i_blkbits);
848 stat->blocks = inode->i_blocks;
853 static int sdcardfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
856 struct dentry *lower_dentry;
858 struct inode *lower_inode;
859 struct path lower_path;
860 struct dentry *parent;
863 parent = dget_parent(dentry);
864 if(!check_caller_access_to_name(d_inode(parent), dentry->d_name.name)) {
865 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
866 " dentry: %s, task:%s\n",
867 __func__, dentry->d_name.name, current->comm);
873 inode = d_inode(dentry);
875 sdcardfs_get_lower_path(dentry, &lower_path);
876 lower_dentry = lower_path.dentry;
877 lower_inode = sdcardfs_lower_inode(inode);
879 sdcardfs_copy_and_fix_attrs(inode, lower_inode);
880 fsstack_copy_inode_size(inode, lower_inode);
882 err = sdcardfs_fillattr(mnt, inode, stat);
883 sdcardfs_put_lower_path(dentry, &lower_path);
887 const struct inode_operations sdcardfs_symlink_iops = {
888 .permission2 = sdcardfs_permission,
889 .setattr2 = sdcardfs_setattr,
890 /* XXX Following operations are implemented,
891 * but FUSE(sdcard) or FAT does not support them
892 * These methods are *NOT* perfectly tested.
893 .readlink = sdcardfs_readlink,
894 .follow_link = sdcardfs_follow_link,
895 .put_link = kfree_put_link,
899 const struct inode_operations sdcardfs_dir_iops = {
900 .create = sdcardfs_create,
901 .lookup = sdcardfs_lookup,
902 .permission = sdcardfs_permission_wrn,
903 .permission2 = sdcardfs_permission,
904 .unlink = sdcardfs_unlink,
905 .mkdir = sdcardfs_mkdir,
906 .rmdir = sdcardfs_rmdir,
907 .rename = sdcardfs_rename,
908 .setattr = sdcardfs_setattr_wrn,
909 .setattr2 = sdcardfs_setattr,
910 .getattr = sdcardfs_getattr,
911 /* XXX Following operations are implemented,
912 * but FUSE(sdcard) or FAT does not support them
913 * These methods are *NOT* perfectly tested.
914 .symlink = sdcardfs_symlink,
915 .link = sdcardfs_link,
916 .mknod = sdcardfs_mknod,
920 const struct inode_operations sdcardfs_main_iops = {
921 .permission = sdcardfs_permission_wrn,
922 .permission2 = sdcardfs_permission,
923 .setattr = sdcardfs_setattr_wrn,
924 .setattr2 = sdcardfs_setattr,
925 .getattr = sdcardfs_getattr,