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 = sbi->options.fs_low_uid;
34 cred->fsgid = 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 int mode, struct nameidata *nd)
55 struct dentry *lower_dentry;
56 struct dentry *lower_parent_dentry = NULL;
57 struct path lower_path, saved_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 err = mnt_want_write(lower_path.mnt);
81 pathcpy(&saved_path, &nd->path);
82 pathcpy(&nd->path, &lower_path);
84 /* set last 16bytes of mode field to 0664 */
85 mode = (mode & S_IFMT) | 00664;
86 err = vfs_create(lower_parent_dentry->d_inode, lower_dentry, mode, nd);
88 pathcpy(&nd->path, &saved_path);
92 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
95 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
96 fsstack_copy_inode_size(dir, lower_parent_dentry->d_inode);
99 mnt_drop_write(lower_path.mnt);
101 unlock_dir(lower_parent_dentry);
102 sdcardfs_put_lower_path(dentry, &lower_path);
103 REVERT_CRED(saved_cred);
109 static int sdcardfs_link(struct dentry *old_dentry, struct inode *dir,
110 struct dentry *new_dentry)
112 struct dentry *lower_old_dentry;
113 struct dentry *lower_new_dentry;
114 struct dentry *lower_dir_dentry;
117 struct path lower_old_path, lower_new_path;
119 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb));
121 file_size_save = i_size_read(old_dentry->d_inode);
122 sdcardfs_get_lower_path(old_dentry, &lower_old_path);
123 sdcardfs_get_lower_path(new_dentry, &lower_new_path);
124 lower_old_dentry = lower_old_path.dentry;
125 lower_new_dentry = lower_new_path.dentry;
126 lower_dir_dentry = lock_parent(lower_new_dentry);
128 err = mnt_want_write(lower_new_path.mnt);
132 err = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
134 if (err || !lower_new_dentry->d_inode)
137 err = sdcardfs_interpose(new_dentry, dir->i_sb, &lower_new_path);
140 fsstack_copy_attr_times(dir, lower_new_dentry->d_inode);
141 fsstack_copy_inode_size(dir, lower_new_dentry->d_inode);
142 old_dentry->d_inode->i_nlink =
143 sdcardfs_lower_inode(old_dentry->d_inode)->i_nlink;
144 i_size_write(new_dentry->d_inode, file_size_save);
146 mnt_drop_write(lower_new_path.mnt);
148 unlock_dir(lower_dir_dentry);
149 sdcardfs_put_lower_path(old_dentry, &lower_old_path);
150 sdcardfs_put_lower_path(new_dentry, &lower_new_path);
156 static int sdcardfs_unlink(struct inode *dir, struct dentry *dentry)
159 struct dentry *lower_dentry;
160 struct inode *lower_dir_inode = sdcardfs_lower_inode(dir);
161 struct dentry *lower_dir_dentry;
162 struct path lower_path;
163 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
164 const struct cred *saved_cred = NULL;
166 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
167 if(!check_caller_access_to_name(dir, dentry->d_name.name, sbi->options.derive, 1, has_rw)) {
168 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
169 " dentry: %s, task:%s\n",
170 __func__, dentry->d_name.name, current->comm);
175 /* save current_cred and override it */
176 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred);
178 sdcardfs_get_lower_path(dentry, &lower_path);
179 lower_dentry = lower_path.dentry;
181 lower_dir_dentry = lock_parent(lower_dentry);
183 err = mnt_want_write(lower_path.mnt);
186 err = vfs_unlink(lower_dir_inode, lower_dentry);
189 * Note: unlinking on top of NFS can cause silly-renamed files.
190 * Trying to delete such files results in EBUSY from NFS
191 * below. Silly-renamed files will get deleted by NFS later on, so
192 * we just need to detect them here and treat such EBUSY errors as
193 * if the upper file was successfully deleted.
195 if (err == -EBUSY && lower_dentry->d_flags & DCACHE_NFSFS_RENAMED)
199 fsstack_copy_attr_times(dir, lower_dir_inode);
200 fsstack_copy_inode_size(dir, lower_dir_inode);
201 dentry->d_inode->i_nlink =
202 sdcardfs_lower_inode(dentry->d_inode)->i_nlink;
203 dentry->d_inode->i_ctime = dir->i_ctime;
204 d_drop(dentry); /* this is needed, else LTP fails (VFS won't do it) */
206 mnt_drop_write(lower_path.mnt);
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 = mnt_want_write(lower_path.mnt);
234 err = vfs_symlink(lower_parent_dentry->d_inode, lower_dentry, symname);
237 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
240 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
241 fsstack_copy_inode_size(dir, lower_parent_dentry->d_inode);
244 mnt_drop_write(lower_path.mnt);
246 unlock_dir(lower_parent_dentry);
247 sdcardfs_put_lower_path(dentry, &lower_path);
253 static int touch(char *abs_path, mode_t mode) {
254 struct file *filp = filp_open(abs_path, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, mode);
256 if (PTR_ERR(filp) == -EEXIST) {
260 printk(KERN_ERR "sdcardfs: failed to open(%s): %ld\n",
261 abs_path, PTR_ERR(filp));
262 return PTR_ERR(filp);
265 filp_close(filp, current->files);
269 static int sdcardfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
272 int make_nomedia_in_obb = 0;
273 struct dentry *lower_dentry;
274 struct dentry *lower_parent_dentry = NULL;
275 struct path lower_path;
276 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
277 const struct cred *saved_cred = NULL;
278 struct sdcardfs_inode_info *pi = SDCARDFS_I(dir);
280 char *nomedia_dir_name;
281 char *nomedia_fullpath;
282 int fullpath_namelen;
285 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
286 if(!check_caller_access_to_name(dir, dentry->d_name.name, sbi->options.derive, 1, has_rw)) {
287 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
288 " dentry: %s, task:%s\n",
289 __func__, dentry->d_name.name, current->comm);
294 /* save current_cred and override it */
295 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred);
297 /* check disk space */
298 if (!check_min_free_space(dentry, 0, 1)) {
299 printk(KERN_INFO "sdcardfs: No minimum free space.\n");
304 /* the lower_dentry is negative here */
305 sdcardfs_get_lower_path(dentry, &lower_path);
306 lower_dentry = lower_path.dentry;
307 lower_parent_dentry = lock_parent(lower_dentry);
309 err = mnt_want_write(lower_path.mnt);
313 /* set last 16bytes of mode field to 0775 */
314 mode = (mode & S_IFMT) | 00775;
315 err = vfs_mkdir(lower_parent_dentry->d_inode, lower_dentry, mode);
320 /* if it is a local obb dentry, setup it with the base obbpath */
321 if(need_graft_path(dentry)) {
323 err = setup_obb_dentry(dentry, &lower_path);
325 /* if the sbi->obbpath is not available, the lower_path won't be
326 * changed by setup_obb_dentry() but the lower path is saved to
327 * its orig_path. this dentry will be revalidated later.
328 * but now, the lower_path should be NULL */
329 sdcardfs_put_reset_lower_path(dentry);
331 /* the newly created lower path which saved to its orig_path or
332 * the lower_path is the base obbpath.
333 * therefore, an additional path_get is required */
334 path_get(&lower_path);
336 make_nomedia_in_obb = 1;
339 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
343 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
344 fsstack_copy_inode_size(dir, lower_parent_dentry->d_inode);
345 /* update number of links on parent directory */
346 dir->i_nlink = sdcardfs_lower_inode(dir)->i_nlink;
348 if ((sbi->options.derive == DERIVE_UNIFIED) && (!strcasecmp(dentry->d_name.name, "obb"))
349 && (pi->perm == PERM_ANDROID) && (pi->userid == 0))
350 make_nomedia_in_obb = 1;
352 /* When creating /Android/data and /Android/obb, mark them as .nomedia */
353 if (make_nomedia_in_obb ||
354 ((pi->perm == PERM_ANDROID) && (!strcasecmp(dentry->d_name.name, "data")))) {
356 page_buf = (char *)__get_free_page(GFP_KERNEL);
358 printk(KERN_ERR "sdcardfs: failed to allocate page buf\n");
362 nomedia_dir_name = d_absolute_path(&lower_path, page_buf, PAGE_SIZE);
363 if (IS_ERR(nomedia_dir_name)) {
364 free_page((unsigned long)page_buf);
365 printk(KERN_ERR "sdcardfs: failed to get .nomedia dir name\n");
369 fullpath_namelen = page_buf + PAGE_SIZE - nomedia_dir_name - 1;
370 fullpath_namelen += strlen("/.nomedia");
371 nomedia_fullpath = kzalloc(fullpath_namelen + 1, GFP_KERNEL);
372 if (!nomedia_fullpath) {
373 free_page((unsigned long)page_buf);
374 printk(KERN_ERR "sdcardfs: failed to allocate .nomedia fullpath buf\n");
378 strcpy(nomedia_fullpath, nomedia_dir_name);
379 free_page((unsigned long)page_buf);
380 strcat(nomedia_fullpath, "/.nomedia");
381 touch_err = touch(nomedia_fullpath, 0664);
383 printk(KERN_ERR "sdcardfs: failed to touch(%s): %d\n",
384 nomedia_fullpath, touch_err);
385 kfree(nomedia_fullpath);
388 kfree(nomedia_fullpath);
391 mnt_drop_write(lower_path.mnt);
393 unlock_dir(lower_parent_dentry);
394 sdcardfs_put_lower_path(dentry, &lower_path);
396 REVERT_CRED(saved_cred);
401 static int sdcardfs_rmdir(struct inode *dir, struct dentry *dentry)
403 struct dentry *lower_dentry;
404 struct dentry *lower_dir_dentry;
406 struct path lower_path;
407 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
408 const struct cred *saved_cred = NULL;
409 //char *path_s = NULL;
411 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
412 if(!check_caller_access_to_name(dir, dentry->d_name.name, sbi->options.derive, 1, has_rw)) {
413 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
414 " dentry: %s, task:%s\n",
415 __func__, dentry->d_name.name, current->comm);
420 /* save current_cred and override it */
421 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred);
423 /* sdcardfs_get_real_lower(): in case of remove an user's obb dentry
424 * the dentry on the original path should be deleted. */
425 sdcardfs_get_real_lower(dentry, &lower_path);
427 lower_dentry = lower_path.dentry;
428 lower_dir_dentry = lock_parent(lower_dentry);
430 err = mnt_want_write(lower_path.mnt);
433 err = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
437 d_drop(dentry); /* drop our dentry on success (why not VFS's job?) */
439 clear_nlink(dentry->d_inode);
440 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
441 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
442 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink;
445 mnt_drop_write(lower_path.mnt);
447 unlock_dir(lower_dir_dentry);
448 sdcardfs_put_real_lower(dentry, &lower_path);
449 REVERT_CRED(saved_cred);
455 static int sdcardfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
459 struct dentry *lower_dentry;
460 struct dentry *lower_parent_dentry = NULL;
461 struct path lower_path;
463 OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb));
465 sdcardfs_get_lower_path(dentry, &lower_path);
466 lower_dentry = lower_path.dentry;
467 lower_parent_dentry = lock_parent(lower_dentry);
469 err = mnt_want_write(lower_path.mnt);
472 err = vfs_mknod(lower_parent_dentry->d_inode, lower_dentry, mode, dev);
476 err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path);
479 fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir));
480 fsstack_copy_inode_size(dir, lower_parent_dentry->d_inode);
483 mnt_drop_write(lower_path.mnt);
485 unlock_dir(lower_parent_dentry);
486 sdcardfs_put_lower_path(dentry, &lower_path);
493 * The locking rules in sdcardfs_rename are complex. We could use a simpler
494 * superblock-level name-space lock for renames and copy-ups.
496 static int sdcardfs_rename(struct inode *old_dir, struct dentry *old_dentry,
497 struct inode *new_dir, struct dentry *new_dentry)
500 struct dentry *lower_old_dentry = NULL;
501 struct dentry *lower_new_dentry = NULL;
502 struct dentry *lower_old_dir_dentry = NULL;
503 struct dentry *lower_new_dir_dentry = NULL;
504 struct dentry *trap = NULL;
505 struct dentry *new_parent = NULL;
506 struct path lower_old_path, lower_new_path;
507 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(old_dentry->d_sb);
508 const struct cred *saved_cred = NULL;
510 int has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
511 if(!check_caller_access_to_name(old_dir, old_dentry->d_name.name,
512 sbi->options.derive, 1, has_rw) ||
513 !check_caller_access_to_name(new_dir, new_dentry->d_name.name,
514 sbi->options.derive, 1, has_rw)) {
515 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
516 " new_dentry: %s, task:%s\n",
517 __func__, new_dentry->d_name.name, current->comm);
522 /* save current_cred and override it */
523 OVERRIDE_CRED(SDCARDFS_SB(old_dir->i_sb), saved_cred);
525 sdcardfs_get_real_lower(old_dentry, &lower_old_path);
526 sdcardfs_get_lower_path(new_dentry, &lower_new_path);
527 lower_old_dentry = lower_old_path.dentry;
528 lower_new_dentry = lower_new_path.dentry;
529 lower_old_dir_dentry = dget_parent(lower_old_dentry);
530 lower_new_dir_dentry = dget_parent(lower_new_dentry);
532 trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
533 /* source should not be ancestor of target */
534 if (trap == lower_old_dentry) {
538 /* target should not be ancestor of source */
539 if (trap == lower_new_dentry) {
544 err = mnt_want_write(lower_old_path.mnt);
547 err = mnt_want_write(lower_new_path.mnt);
549 goto out_drop_old_write;
551 err = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
552 lower_new_dir_dentry->d_inode, lower_new_dentry);
556 /* Copy attrs from lower dir, but i_uid/i_gid */
557 fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode);
558 fsstack_copy_inode_size(new_dir, lower_new_dir_dentry->d_inode);
559 fix_derived_permission(new_dir);
560 if (new_dir != old_dir) {
561 fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode);
562 fsstack_copy_inode_size(old_dir, lower_old_dir_dentry->d_inode);
563 fix_derived_permission(old_dir);
564 /* update the derived permission of the old_dentry
565 * with its new parent
567 new_parent = dget_parent(new_dentry);
569 if(old_dentry->d_inode) {
570 get_derived_permission(new_parent, old_dentry);
571 fix_derived_permission(old_dentry->d_inode);
578 mnt_drop_write(lower_new_path.mnt);
580 mnt_drop_write(lower_old_path.mnt);
582 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
583 dput(lower_old_dir_dentry);
584 dput(lower_new_dir_dentry);
585 sdcardfs_put_real_lower(old_dentry, &lower_old_path);
586 sdcardfs_put_lower_path(new_dentry, &lower_new_path);
587 REVERT_CRED(saved_cred);
593 static int sdcardfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
596 struct dentry *lower_dentry;
597 struct path lower_path;
598 /* XXX readlink does not requires overriding credential */
600 sdcardfs_get_lower_path(dentry, &lower_path);
601 lower_dentry = lower_path.dentry;
602 if (!lower_dentry->d_inode->i_op ||
603 !lower_dentry->d_inode->i_op->readlink) {
608 err = lower_dentry->d_inode->i_op->readlink(lower_dentry,
612 fsstack_copy_attr_atime(dentry->d_inode, lower_dentry->d_inode);
615 sdcardfs_put_lower_path(dentry, &lower_path);
621 static void *sdcardfs_follow_link(struct dentry *dentry, struct nameidata *nd)
624 int len = PAGE_SIZE, err;
627 /* This is freed by the put_link method assuming a successful call. */
628 buf = kmalloc(len, GFP_KERNEL);
630 buf = ERR_PTR(-ENOMEM);
634 /* read the symlink, and then we will follow it */
637 err = sdcardfs_readlink(dentry, buf, len);
646 nd_set_link(nd, buf);
652 /* this @nd *IS* still used */
653 static void sdcardfs_put_link(struct dentry *dentry, struct nameidata *nd,
656 char *buf = nd_get_link(nd);
657 if (!IS_ERR(buf)) /* free the char* */
662 static int sdcardfs_permission(struct inode *inode, int mask, unsigned int flags)
666 if (flags & IPERM_FLAG_RCU)
670 * Permission check on sdcardfs inode.
671 * Calling process should have AID_SDCARD_RW permission
673 err = generic_permission(inode, mask, 0, inode->i_op->check_acl);
676 * Original sdcardfs code calls inode_permission(lower_inode,.. )
677 * for checking inode permission. But doing such things here seems
678 * duplicated work, because the functions called after this func,
679 * such as vfs_create, vfs_unlink, vfs_rename, and etc,
680 * does exactly same thing, i.e., they calls inode_permission().
681 * So we just let they do the things.
682 * If there are any security hole, just uncomment following if block.
687 * Permission check on lower_inode(=EXT4).
688 * we check it with AID_MEDIA_RW permission
690 struct inode *lower_inode;
691 OVERRIDE_CRED(SDCARDFS_SB(inode->sb));
693 lower_inode = sdcardfs_lower_inode(inode);
694 err = inode_permission(lower_inode, mask);
703 static int sdcardfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
706 struct dentry *lower_dentry;
708 struct inode *lower_inode;
709 struct path lower_path;
710 struct dentry *parent;
711 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
713 parent = dget_parent(dentry);
714 if(!check_caller_access_to_name(parent->d_inode, dentry->d_name.name,
715 sbi->options.derive, 0, 0)) {
716 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
717 " dentry: %s, task:%s\n",
718 __func__, dentry->d_name.name, current->comm);
724 inode = dentry->d_inode;
726 sdcardfs_get_lower_path(dentry, &lower_path);
727 lower_dentry = lower_path.dentry;
728 lower_inode = sdcardfs_lower_inode(inode);
730 fsstack_copy_attr_all(inode, lower_inode);
731 fsstack_copy_inode_size(inode, lower_inode);
732 /* if the dentry has been moved from other location
733 * so, on this stage, its derived permission must be
734 * rechecked from its private field.
736 fix_derived_permission(inode);
738 generic_fillattr(inode, stat);
739 sdcardfs_put_lower_path(dentry, &lower_path);
743 static int sdcardfs_setattr(struct dentry *dentry, struct iattr *ia)
746 struct dentry *lower_dentry;
748 struct inode *lower_inode;
749 struct path lower_path;
750 struct iattr lower_ia;
751 struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
752 struct dentry *parent;
755 inode = dentry->d_inode;
758 * Check if user has permission to change inode. We don't check if
759 * this user can change the lower inode: that should happen when
760 * calling notify_change on the lower inode.
762 err = inode_change_ok(inode, ia);
764 /* no vfs_XXX operations required, cred overriding will be skipped. wj*/
766 /* check the Android group ID */
767 has_rw = get_caller_has_rw_locked(sbi->pkgl_id, sbi->options.derive);
768 parent = dget_parent(dentry);
769 if(!check_caller_access_to_name(parent->d_inode, dentry->d_name.name,
770 sbi->options.derive, 1, has_rw)) {
771 printk(KERN_INFO "%s: need to check the caller's gid in packages.list\n"
772 " dentry: %s, task:%s\n",
773 __func__, dentry->d_name.name, current->comm);
782 sdcardfs_get_lower_path(dentry, &lower_path);
783 lower_dentry = lower_path.dentry;
784 lower_inode = sdcardfs_lower_inode(inode);
786 /* prepare our own lower struct iattr (with the lower file) */
787 memcpy(&lower_ia, ia, sizeof(lower_ia));
788 if (ia->ia_valid & ATTR_FILE)
789 lower_ia.ia_file = sdcardfs_lower_file(ia->ia_file);
791 lower_ia.ia_valid &= ~(ATTR_UID | ATTR_GID | ATTR_MODE);
794 * If shrinking, first truncate upper level to cancel writing dirty
795 * pages beyond the new eof; and also if its' maxbytes is more
796 * limiting (fail with -EFBIG before making any change to the lower
797 * level). There is no need to vmtruncate the upper level
798 * afterwards in the other cases: we fsstack_copy_inode_size from
802 down_write(¤t->mm->mmap_sem);
803 if (ia->ia_valid & ATTR_SIZE) {
804 err = inode_newsize_ok(inode, ia->ia_size);
807 up_write(¤t->mm->mmap_sem);
810 truncate_setsize(inode, ia->ia_size);
814 * mode change is for clearing setuid/setgid bits. Allow lower fs
815 * to interpret this in its own way.
817 if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
818 lower_ia.ia_valid &= ~ATTR_MODE;
820 /* notify the (possibly copied-up) lower inode */
822 * Note: we use lower_dentry->d_inode, because lower_inode may be
823 * unlinked (no inode->i_sb and i_ino==0. This happens if someone
824 * tries to open(), unlink(), then ftruncate() a file.
826 mutex_lock(&lower_dentry->d_inode->i_mutex);
827 err = notify_change(lower_dentry, &lower_ia); /* note: lower_ia */
828 mutex_unlock(&lower_dentry->d_inode->i_mutex);
830 up_write(¤t->mm->mmap_sem);
834 /* get attributes from the lower inode */
835 fsstack_copy_attr_all(inode, lower_inode);
836 /* update derived permission of the upper inode */
837 fix_derived_permission(inode);
840 * Not running fsstack_copy_inode_size(inode, lower_inode), because
841 * VFS should update our inode size, and notify_change on
842 * lower_inode should update its size.
846 sdcardfs_put_lower_path(dentry, &lower_path);
851 const struct inode_operations sdcardfs_symlink_iops = {
852 .permission = sdcardfs_permission,
853 .setattr = sdcardfs_setattr,
854 /* XXX Following operations are implemented,
855 * but FUSE(sdcard) or FAT does not support them
856 * These methods are *NOT* perfectly tested.
857 .readlink = sdcardfs_readlink,
858 .follow_link = sdcardfs_follow_link,
859 .put_link = sdcardfs_put_link,
863 const struct inode_operations sdcardfs_dir_iops = {
864 .create = sdcardfs_create,
865 .lookup = sdcardfs_lookup,
866 .permission = sdcardfs_permission,
867 .unlink = sdcardfs_unlink,
868 .mkdir = sdcardfs_mkdir,
869 .rmdir = sdcardfs_rmdir,
870 .rename = sdcardfs_rename,
871 .setattr = sdcardfs_setattr,
872 .getattr = sdcardfs_getattr,
873 /* XXX Following operations are implemented,
874 * but FUSE(sdcard) or FAT does not support them
875 * These methods are *NOT* perfectly tested.
876 .symlink = sdcardfs_symlink,
877 .link = sdcardfs_link,
878 .mknod = sdcardfs_mknod,
882 const struct inode_operations sdcardfs_main_iops = {
883 .permission = sdcardfs_permission,
884 .setattr = sdcardfs_setattr,
885 .getattr = sdcardfs_getattr,