Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/sdcardfs/inode.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" |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 22 | #include <linux/fs_struct.h> |
Daniel Rosenberg | b434e57 | 2017-03-02 18:07:21 -0800 | [diff] [blame] | 23 | #include <linux/ratelimit.h> |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 24 | |
| 25 | /* Do not directly use this function. Use OVERRIDE_CRED() instead. */ |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 26 | const struct cred *override_fsids(struct sdcardfs_sb_info *sbi, |
| 27 | struct sdcardfs_inode_data *data) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 28 | { |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 29 | struct cred *cred; |
| 30 | const struct cred *old_cred; |
| 31 | uid_t uid; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 32 | |
| 33 | cred = prepare_creds(); |
| 34 | if (!cred) |
| 35 | return NULL; |
| 36 | |
Daniel Rosenberg | 7d10e43 | 2017-07-19 17:25:07 -0700 | [diff] [blame] | 37 | if (sbi->options.gid_derivation) { |
| 38 | if (data->under_obb) |
| 39 | uid = AID_MEDIA_OBB; |
| 40 | else |
| 41 | uid = multiuser_get_uid(data->userid, sbi->options.fs_low_uid); |
| 42 | } else { |
| 43 | uid = sbi->options.fs_low_uid; |
| 44 | } |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 45 | cred->fsuid = make_kuid(&init_user_ns, uid); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 46 | cred->fsgid = make_kgid(&init_user_ns, sbi->options.fs_low_gid); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 47 | |
| 48 | old_cred = override_creds(cred); |
| 49 | |
| 50 | return old_cred; |
| 51 | } |
| 52 | |
| 53 | /* Do not directly use this function, use REVERT_CRED() instead. */ |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 54 | void revert_fsids(const struct cred *old_cred) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 55 | { |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 56 | const struct cred *cur_cred; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 57 | |
| 58 | cur_cred = current->cred; |
| 59 | revert_creds(old_cred); |
| 60 | put_cred(cur_cred); |
| 61 | } |
| 62 | |
| 63 | static int sdcardfs_create(struct inode *dir, struct dentry *dentry, |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 64 | umode_t mode, bool want_excl) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 65 | { |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 66 | int err; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 67 | struct dentry *lower_dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 68 | struct vfsmount *lower_dentry_mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 69 | struct dentry *lower_parent_dentry = NULL; |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 70 | struct path lower_path; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 71 | const struct cred *saved_cred = NULL; |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 72 | struct fs_struct *saved_fs; |
| 73 | struct fs_struct *copied_fs; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 74 | |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 75 | if (!check_caller_access_to_name(dir, &dentry->d_name)) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 76 | err = -EACCES; |
| 77 | goto out_eacces; |
| 78 | } |
| 79 | |
| 80 | /* save current_cred and override it */ |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 81 | OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(dir)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 82 | |
| 83 | sdcardfs_get_lower_path(dentry, &lower_path); |
| 84 | lower_dentry = lower_path.dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 85 | lower_dentry_mnt = lower_path.mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 86 | lower_parent_dentry = lock_parent(lower_dentry); |
| 87 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 88 | /* set last 16bytes of mode field to 0664 */ |
| 89 | mode = (mode & S_IFMT) | 00664; |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 90 | |
| 91 | /* temporarily change umask for lower fs write */ |
| 92 | saved_fs = current->fs; |
| 93 | copied_fs = copy_fs_struct(current->fs); |
| 94 | if (!copied_fs) { |
| 95 | err = -ENOMEM; |
| 96 | goto out_unlock; |
| 97 | } |
| 98 | current->fs = copied_fs; |
| 99 | current->fs->umask = 0; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 100 | err = vfs_create2(lower_dentry_mnt, d_inode(lower_parent_dentry), lower_dentry, mode, want_excl); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 101 | if (err) |
| 102 | goto out; |
| 103 | |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 104 | err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path, |
| 105 | SDCARDFS_I(dir)->data->userid); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 106 | if (err) |
| 107 | goto out; |
| 108 | fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir)); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 109 | fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry)); |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 110 | fixup_lower_ownership(dentry, dentry->d_name.name); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 111 | |
| 112 | out: |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 113 | current->fs = saved_fs; |
| 114 | free_fs_struct(copied_fs); |
| 115 | out_unlock: |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 116 | unlock_dir(lower_parent_dentry); |
| 117 | sdcardfs_put_lower_path(dentry, &lower_path); |
| 118 | REVERT_CRED(saved_cred); |
| 119 | out_eacces: |
| 120 | return err; |
| 121 | } |
| 122 | |
| 123 | #if 0 |
| 124 | static int sdcardfs_link(struct dentry *old_dentry, struct inode *dir, |
| 125 | struct dentry *new_dentry) |
| 126 | { |
| 127 | struct dentry *lower_old_dentry; |
| 128 | struct dentry *lower_new_dentry; |
| 129 | struct dentry *lower_dir_dentry; |
| 130 | u64 file_size_save; |
| 131 | int err; |
| 132 | struct path lower_old_path, lower_new_path; |
| 133 | |
| 134 | OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb)); |
| 135 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 136 | file_size_save = i_size_read(d_inode(old_dentry)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 137 | sdcardfs_get_lower_path(old_dentry, &lower_old_path); |
| 138 | sdcardfs_get_lower_path(new_dentry, &lower_new_path); |
| 139 | lower_old_dentry = lower_old_path.dentry; |
| 140 | lower_new_dentry = lower_new_path.dentry; |
| 141 | lower_dir_dentry = lock_parent(lower_new_dentry); |
| 142 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 143 | err = vfs_link(lower_old_dentry, d_inode(lower_dir_dentry), |
| 144 | lower_new_dentry, NULL); |
| 145 | if (err || !d_inode(lower_new_dentry)) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 146 | goto out; |
| 147 | |
| 148 | err = sdcardfs_interpose(new_dentry, dir->i_sb, &lower_new_path); |
| 149 | if (err) |
| 150 | goto out; |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 151 | fsstack_copy_attr_times(dir, d_inode(lower_new_dentry)); |
| 152 | fsstack_copy_inode_size(dir, d_inode(lower_new_dentry)); |
| 153 | set_nlink(d_inode(old_dentry), |
| 154 | sdcardfs_lower_inode(d_inode(old_dentry))->i_nlink); |
| 155 | i_size_write(d_inode(new_dentry), file_size_save); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 156 | out: |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 157 | unlock_dir(lower_dir_dentry); |
| 158 | sdcardfs_put_lower_path(old_dentry, &lower_old_path); |
| 159 | sdcardfs_put_lower_path(new_dentry, &lower_new_path); |
| 160 | REVERT_CRED(); |
| 161 | return err; |
| 162 | } |
| 163 | #endif |
| 164 | |
| 165 | static int sdcardfs_unlink(struct inode *dir, struct dentry *dentry) |
| 166 | { |
| 167 | int err; |
| 168 | struct dentry *lower_dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 169 | struct vfsmount *lower_mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 170 | struct inode *lower_dir_inode = sdcardfs_lower_inode(dir); |
| 171 | struct dentry *lower_dir_dentry; |
| 172 | struct path lower_path; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 173 | const struct cred *saved_cred = NULL; |
| 174 | |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 175 | if (!check_caller_access_to_name(dir, &dentry->d_name)) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 176 | err = -EACCES; |
| 177 | goto out_eacces; |
| 178 | } |
| 179 | |
| 180 | /* save current_cred and override it */ |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 181 | OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(dir)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 182 | |
| 183 | sdcardfs_get_lower_path(dentry, &lower_path); |
| 184 | lower_dentry = lower_path.dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 185 | lower_mnt = lower_path.mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 186 | dget(lower_dentry); |
| 187 | lower_dir_dentry = lock_parent(lower_dentry); |
| 188 | |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 189 | err = vfs_unlink2(lower_mnt, lower_dir_inode, lower_dentry, NULL); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * Note: unlinking on top of NFS can cause silly-renamed files. |
| 193 | * Trying to delete such files results in EBUSY from NFS |
| 194 | * below. Silly-renamed files will get deleted by NFS later on, so |
| 195 | * we just need to detect them here and treat such EBUSY errors as |
| 196 | * if the upper file was successfully deleted. |
| 197 | */ |
| 198 | if (err == -EBUSY && lower_dentry->d_flags & DCACHE_NFSFS_RENAMED) |
| 199 | err = 0; |
| 200 | if (err) |
| 201 | goto out; |
| 202 | fsstack_copy_attr_times(dir, lower_dir_inode); |
| 203 | fsstack_copy_inode_size(dir, lower_dir_inode); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 204 | set_nlink(d_inode(dentry), |
| 205 | sdcardfs_lower_inode(d_inode(dentry))->i_nlink); |
| 206 | d_inode(dentry)->i_ctime = dir->i_ctime; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 207 | d_drop(dentry); /* this is needed, else LTP fails (VFS won't do it) */ |
| 208 | out: |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 209 | unlock_dir(lower_dir_dentry); |
| 210 | dput(lower_dentry); |
| 211 | sdcardfs_put_lower_path(dentry, &lower_path); |
| 212 | REVERT_CRED(saved_cred); |
| 213 | out_eacces: |
| 214 | return err; |
| 215 | } |
| 216 | |
| 217 | #if 0 |
| 218 | static int sdcardfs_symlink(struct inode *dir, struct dentry *dentry, |
| 219 | const char *symname) |
| 220 | { |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 221 | int err; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 222 | struct dentry *lower_dentry; |
| 223 | struct dentry *lower_parent_dentry = NULL; |
| 224 | struct path lower_path; |
| 225 | |
| 226 | OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb)); |
| 227 | |
| 228 | sdcardfs_get_lower_path(dentry, &lower_path); |
| 229 | lower_dentry = lower_path.dentry; |
| 230 | lower_parent_dentry = lock_parent(lower_dentry); |
| 231 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 232 | err = vfs_symlink(d_inode(lower_parent_dentry), lower_dentry, symname); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 233 | if (err) |
| 234 | goto out; |
| 235 | err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path); |
| 236 | if (err) |
| 237 | goto out; |
| 238 | fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir)); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 239 | fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 240 | |
| 241 | out: |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 242 | unlock_dir(lower_parent_dentry); |
| 243 | sdcardfs_put_lower_path(dentry, &lower_path); |
| 244 | REVERT_CRED(); |
| 245 | return err; |
| 246 | } |
| 247 | #endif |
| 248 | |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 249 | static int touch(char *abs_path, mode_t mode) |
| 250 | { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 251 | struct file *filp = filp_open(abs_path, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, mode); |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 252 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 253 | if (IS_ERR(filp)) { |
| 254 | if (PTR_ERR(filp) == -EEXIST) { |
| 255 | return 0; |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 256 | } else { |
Daniel Rosenberg | 77ecf21 | 2017-03-16 17:46:13 -0700 | [diff] [blame] | 257 | pr_err("sdcardfs: failed to open(%s): %ld\n", |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 258 | abs_path, PTR_ERR(filp)); |
| 259 | return PTR_ERR(filp); |
| 260 | } |
| 261 | } |
| 262 | filp_close(filp, current->files); |
| 263 | return 0; |
| 264 | } |
| 265 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 266 | static int sdcardfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 267 | { |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 268 | int err; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 269 | int make_nomedia_in_obb = 0; |
| 270 | struct dentry *lower_dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 271 | struct vfsmount *lower_mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 272 | struct dentry *lower_parent_dentry = NULL; |
| 273 | struct path lower_path; |
| 274 | struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb); |
| 275 | const struct cred *saved_cred = NULL; |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 276 | struct sdcardfs_inode_data *pd = SDCARDFS_I(dir)->data; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 277 | int touch_err = 0; |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 278 | struct fs_struct *saved_fs; |
| 279 | struct fs_struct *copied_fs; |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 280 | struct qstr q_obb = QSTR_LITERAL("obb"); |
| 281 | struct qstr q_data = QSTR_LITERAL("data"); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 282 | |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 283 | if (!check_caller_access_to_name(dir, &dentry->d_name)) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 284 | err = -EACCES; |
| 285 | goto out_eacces; |
| 286 | } |
| 287 | |
| 288 | /* save current_cred and override it */ |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 289 | OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(dir)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 290 | |
| 291 | /* check disk space */ |
| 292 | if (!check_min_free_space(dentry, 0, 1)) { |
Daniel Rosenberg | 77ecf21 | 2017-03-16 17:46:13 -0700 | [diff] [blame] | 293 | pr_err("sdcardfs: No minimum free space.\n"); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 294 | err = -ENOSPC; |
| 295 | goto out_revert; |
| 296 | } |
| 297 | |
| 298 | /* the lower_dentry is negative here */ |
| 299 | sdcardfs_get_lower_path(dentry, &lower_path); |
| 300 | lower_dentry = lower_path.dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 301 | lower_mnt = lower_path.mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 302 | lower_parent_dentry = lock_parent(lower_dentry); |
| 303 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 304 | /* set last 16bytes of mode field to 0775 */ |
| 305 | mode = (mode & S_IFMT) | 00775; |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 306 | |
| 307 | /* temporarily change umask for lower fs write */ |
| 308 | saved_fs = current->fs; |
| 309 | copied_fs = copy_fs_struct(current->fs); |
| 310 | if (!copied_fs) { |
| 311 | err = -ENOMEM; |
Daniel Rosenberg | 9480415 | 2016-09-26 14:48:22 -0700 | [diff] [blame] | 312 | unlock_dir(lower_parent_dentry); |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 313 | goto out_unlock; |
| 314 | } |
| 315 | current->fs = copied_fs; |
| 316 | current->fs->umask = 0; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 317 | err = vfs_mkdir2(lower_mnt, d_inode(lower_parent_dentry), lower_dentry, mode); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 318 | |
Daniel Rosenberg | 9480415 | 2016-09-26 14:48:22 -0700 | [diff] [blame] | 319 | if (err) { |
| 320 | unlock_dir(lower_parent_dentry); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 321 | goto out; |
Daniel Rosenberg | 9480415 | 2016-09-26 14:48:22 -0700 | [diff] [blame] | 322 | } |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 323 | |
| 324 | /* if it is a local obb dentry, setup it with the base obbpath */ |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 325 | if (need_graft_path(dentry)) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 326 | |
| 327 | err = setup_obb_dentry(dentry, &lower_path); |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 328 | if (err) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 329 | /* if the sbi->obbpath is not available, the lower_path won't be |
| 330 | * changed by setup_obb_dentry() but the lower path is saved to |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 331 | * its orig_path. this dentry will be revalidated later. |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 332 | * but now, the lower_path should be NULL |
| 333 | */ |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 334 | sdcardfs_put_reset_lower_path(dentry); |
| 335 | |
| 336 | /* the newly created lower path which saved to its orig_path or |
| 337 | * the lower_path is the base obbpath. |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 338 | * therefore, an additional path_get is required |
| 339 | */ |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 340 | path_get(&lower_path); |
| 341 | } else |
| 342 | make_nomedia_in_obb = 1; |
| 343 | } |
| 344 | |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 345 | err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path, pd->userid); |
Daniel Rosenberg | 9480415 | 2016-09-26 14:48:22 -0700 | [diff] [blame] | 346 | if (err) { |
| 347 | unlock_dir(lower_parent_dentry); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 348 | goto out; |
Daniel Rosenberg | 9480415 | 2016-09-26 14:48:22 -0700 | [diff] [blame] | 349 | } |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 350 | |
| 351 | fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir)); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 352 | fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 353 | /* update number of links on parent directory */ |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 354 | set_nlink(dir, sdcardfs_lower_inode(dir)->i_nlink); |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 355 | fixup_lower_ownership(dentry, dentry->d_name.name); |
Daniel Rosenberg | 9480415 | 2016-09-26 14:48:22 -0700 | [diff] [blame] | 356 | unlock_dir(lower_parent_dentry); |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 357 | if ((!sbi->options.multiuser) && (qstr_case_eq(&dentry->d_name, &q_obb)) |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 358 | && (pd->perm == PERM_ANDROID) && (pd->userid == 0)) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 359 | make_nomedia_in_obb = 1; |
| 360 | |
| 361 | /* When creating /Android/data and /Android/obb, mark them as .nomedia */ |
| 362 | if (make_nomedia_in_obb || |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 363 | ((pd->perm == PERM_ANDROID) |
| 364 | && (qstr_case_eq(&dentry->d_name, &q_data)))) { |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 365 | REVERT_CRED(saved_cred); |
| 366 | OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(d_inode(dentry))); |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 367 | set_fs_pwd(current->fs, &lower_path); |
| 368 | touch_err = touch(".nomedia", 0664); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 369 | if (touch_err) { |
Daniel Rosenberg | 77ecf21 | 2017-03-16 17:46:13 -0700 | [diff] [blame] | 370 | pr_err("sdcardfs: failed to create .nomedia in %s: %d\n", |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 371 | lower_path.dentry->d_name.name, touch_err); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 372 | goto out; |
| 373 | } |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 374 | } |
| 375 | out: |
Daniel Rosenberg | 2b31462 | 2016-04-13 16:38:34 -0700 | [diff] [blame] | 376 | current->fs = saved_fs; |
| 377 | free_fs_struct(copied_fs); |
| 378 | out_unlock: |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 379 | sdcardfs_put_lower_path(dentry, &lower_path); |
| 380 | out_revert: |
| 381 | REVERT_CRED(saved_cred); |
| 382 | out_eacces: |
| 383 | return err; |
| 384 | } |
| 385 | |
| 386 | static int sdcardfs_rmdir(struct inode *dir, struct dentry *dentry) |
| 387 | { |
| 388 | struct dentry *lower_dentry; |
| 389 | struct dentry *lower_dir_dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 390 | struct vfsmount *lower_mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 391 | int err; |
| 392 | struct path lower_path; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 393 | const struct cred *saved_cred = NULL; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 394 | |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 395 | if (!check_caller_access_to_name(dir, &dentry->d_name)) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 396 | err = -EACCES; |
| 397 | goto out_eacces; |
| 398 | } |
| 399 | |
| 400 | /* save current_cred and override it */ |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 401 | OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb), saved_cred, SDCARDFS_I(dir)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 402 | |
| 403 | /* sdcardfs_get_real_lower(): in case of remove an user's obb dentry |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 404 | * the dentry on the original path should be deleted. |
| 405 | */ |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 406 | sdcardfs_get_real_lower(dentry, &lower_path); |
| 407 | |
| 408 | lower_dentry = lower_path.dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 409 | lower_mnt = lower_path.mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 410 | lower_dir_dentry = lock_parent(lower_dentry); |
| 411 | |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 412 | err = vfs_rmdir2(lower_mnt, d_inode(lower_dir_dentry), lower_dentry); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 413 | if (err) |
| 414 | goto out; |
| 415 | |
| 416 | d_drop(dentry); /* drop our dentry on success (why not VFS's job?) */ |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 417 | if (d_inode(dentry)) |
| 418 | clear_nlink(d_inode(dentry)); |
| 419 | fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry)); |
| 420 | fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry)); |
| 421 | set_nlink(dir, d_inode(lower_dir_dentry)->i_nlink); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 422 | |
| 423 | out: |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 424 | unlock_dir(lower_dir_dentry); |
| 425 | sdcardfs_put_real_lower(dentry, &lower_path); |
| 426 | REVERT_CRED(saved_cred); |
| 427 | out_eacces: |
| 428 | return err; |
| 429 | } |
| 430 | |
| 431 | #if 0 |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 432 | static int sdcardfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 433 | dev_t dev) |
| 434 | { |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 435 | int err; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 436 | struct dentry *lower_dentry; |
| 437 | struct dentry *lower_parent_dentry = NULL; |
| 438 | struct path lower_path; |
| 439 | |
| 440 | OVERRIDE_CRED(SDCARDFS_SB(dir->i_sb)); |
| 441 | |
| 442 | sdcardfs_get_lower_path(dentry, &lower_path); |
| 443 | lower_dentry = lower_path.dentry; |
| 444 | lower_parent_dentry = lock_parent(lower_dentry); |
| 445 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 446 | err = vfs_mknod(d_inode(lower_parent_dentry), lower_dentry, mode, dev); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 447 | if (err) |
| 448 | goto out; |
| 449 | |
| 450 | err = sdcardfs_interpose(dentry, dir->i_sb, &lower_path); |
| 451 | if (err) |
| 452 | goto out; |
| 453 | fsstack_copy_attr_times(dir, sdcardfs_lower_inode(dir)); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 454 | fsstack_copy_inode_size(dir, d_inode(lower_parent_dentry)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 455 | |
| 456 | out: |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 457 | unlock_dir(lower_parent_dentry); |
| 458 | sdcardfs_put_lower_path(dentry, &lower_path); |
| 459 | REVERT_CRED(); |
| 460 | return err; |
| 461 | } |
| 462 | #endif |
| 463 | |
| 464 | /* |
| 465 | * The locking rules in sdcardfs_rename are complex. We could use a simpler |
| 466 | * superblock-level name-space lock for renames and copy-ups. |
| 467 | */ |
| 468 | static int sdcardfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
Amit Pundir | d4ae31b | 2016-10-16 15:24:15 +0530 | [diff] [blame] | 469 | struct inode *new_dir, struct dentry *new_dentry, |
| 470 | unsigned int flags) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 471 | { |
| 472 | int err = 0; |
| 473 | struct dentry *lower_old_dentry = NULL; |
| 474 | struct dentry *lower_new_dentry = NULL; |
| 475 | struct dentry *lower_old_dir_dentry = NULL; |
| 476 | struct dentry *lower_new_dir_dentry = NULL; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 477 | struct vfsmount *lower_mnt = NULL; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 478 | struct dentry *trap = NULL; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 479 | struct path lower_old_path, lower_new_path; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 480 | const struct cred *saved_cred = NULL; |
| 481 | |
Amit Pundir | d4ae31b | 2016-10-16 15:24:15 +0530 | [diff] [blame] | 482 | if (flags) |
| 483 | return -EINVAL; |
| 484 | |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 485 | if (!check_caller_access_to_name(old_dir, &old_dentry->d_name) || |
| 486 | !check_caller_access_to_name(new_dir, &new_dentry->d_name)) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 487 | err = -EACCES; |
| 488 | goto out_eacces; |
| 489 | } |
| 490 | |
| 491 | /* save current_cred and override it */ |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 492 | OVERRIDE_CRED(SDCARDFS_SB(old_dir->i_sb), saved_cred, SDCARDFS_I(new_dir)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 493 | |
| 494 | sdcardfs_get_real_lower(old_dentry, &lower_old_path); |
| 495 | sdcardfs_get_lower_path(new_dentry, &lower_new_path); |
| 496 | lower_old_dentry = lower_old_path.dentry; |
| 497 | lower_new_dentry = lower_new_path.dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 498 | lower_mnt = lower_old_path.mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 499 | lower_old_dir_dentry = dget_parent(lower_old_dentry); |
| 500 | lower_new_dir_dentry = dget_parent(lower_new_dentry); |
| 501 | |
| 502 | trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
| 503 | /* source should not be ancestor of target */ |
| 504 | if (trap == lower_old_dentry) { |
| 505 | err = -EINVAL; |
| 506 | goto out; |
| 507 | } |
| 508 | /* target should not be ancestor of source */ |
| 509 | if (trap == lower_new_dentry) { |
| 510 | err = -ENOTEMPTY; |
| 511 | goto out; |
| 512 | } |
| 513 | |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 514 | err = vfs_rename2(lower_mnt, |
| 515 | d_inode(lower_old_dir_dentry), lower_old_dentry, |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 516 | d_inode(lower_new_dir_dentry), lower_new_dentry, |
| 517 | NULL, 0); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 518 | if (err) |
| 519 | goto out; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 520 | |
| 521 | /* Copy attrs from lower dir, but i_uid/i_gid */ |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 522 | sdcardfs_copy_and_fix_attrs(new_dir, d_inode(lower_new_dir_dentry)); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 523 | fsstack_copy_inode_size(new_dir, d_inode(lower_new_dir_dentry)); |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 524 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 525 | if (new_dir != old_dir) { |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 526 | sdcardfs_copy_and_fix_attrs(old_dir, d_inode(lower_old_dir_dentry)); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 527 | fsstack_copy_inode_size(old_dir, d_inode(lower_old_dir_dentry)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 528 | } |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 529 | get_derived_permission_new(new_dentry->d_parent, old_dentry, &new_dentry->d_name); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 530 | fixup_tmp_permissions(d_inode(old_dentry)); |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 531 | fixup_lower_ownership(old_dentry, new_dentry->d_name.name); |
Daniel Rosenberg | 64386ed | 2017-03-08 17:45:46 -0800 | [diff] [blame] | 532 | d_invalidate(old_dentry); /* Can't fixup ownership recursively :( */ |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 533 | out: |
| 534 | unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
| 535 | dput(lower_old_dir_dentry); |
| 536 | dput(lower_new_dir_dentry); |
| 537 | sdcardfs_put_real_lower(old_dentry, &lower_old_path); |
| 538 | sdcardfs_put_lower_path(new_dentry, &lower_new_path); |
| 539 | REVERT_CRED(saved_cred); |
| 540 | out_eacces: |
| 541 | return err; |
| 542 | } |
| 543 | |
| 544 | #if 0 |
| 545 | static int sdcardfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz) |
| 546 | { |
| 547 | int err; |
| 548 | struct dentry *lower_dentry; |
| 549 | struct path lower_path; |
| 550 | /* XXX readlink does not requires overriding credential */ |
| 551 | |
| 552 | sdcardfs_get_lower_path(dentry, &lower_path); |
| 553 | lower_dentry = lower_path.dentry; |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 554 | if (!d_inode(lower_dentry)->i_op || |
| 555 | !d_inode(lower_dentry)->i_op->readlink) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 556 | err = -EINVAL; |
| 557 | goto out; |
| 558 | } |
| 559 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 560 | err = d_inode(lower_dentry)->i_op->readlink(lower_dentry, |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 561 | buf, bufsiz); |
| 562 | if (err < 0) |
| 563 | goto out; |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 564 | fsstack_copy_attr_atime(d_inode(dentry), d_inode(lower_dentry)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 565 | |
| 566 | out: |
| 567 | sdcardfs_put_lower_path(dentry, &lower_path); |
| 568 | return err; |
| 569 | } |
| 570 | #endif |
| 571 | |
| 572 | #if 0 |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 573 | static const char *sdcardfs_follow_link(struct dentry *dentry, void **cookie) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 574 | { |
| 575 | char *buf; |
| 576 | int len = PAGE_SIZE, err; |
| 577 | mm_segment_t old_fs; |
| 578 | |
| 579 | /* This is freed by the put_link method assuming a successful call. */ |
| 580 | buf = kmalloc(len, GFP_KERNEL); |
| 581 | if (!buf) { |
| 582 | buf = ERR_PTR(-ENOMEM); |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 583 | return buf; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* read the symlink, and then we will follow it */ |
| 587 | old_fs = get_fs(); |
| 588 | set_fs(KERNEL_DS); |
| 589 | err = sdcardfs_readlink(dentry, buf, len); |
| 590 | set_fs(old_fs); |
| 591 | if (err < 0) { |
| 592 | kfree(buf); |
| 593 | buf = ERR_PTR(err); |
| 594 | } else { |
| 595 | buf[err] = '\0'; |
| 596 | } |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 597 | return *cookie = buf; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 598 | } |
| 599 | #endif |
| 600 | |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 601 | static int sdcardfs_permission_wrn(struct inode *inode, int mask) |
| 602 | { |
Ritesh Harjani | 8af4a38 | 2017-12-05 12:37:43 +0530 | [diff] [blame] | 603 | pr_debug("sdcardfs does not support permission. Use permission2.\n"); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 604 | return -EINVAL; |
| 605 | } |
| 606 | |
| 607 | void copy_attrs(struct inode *dest, const struct inode *src) |
| 608 | { |
| 609 | dest->i_mode = src->i_mode; |
| 610 | dest->i_uid = src->i_uid; |
| 611 | dest->i_gid = src->i_gid; |
| 612 | dest->i_rdev = src->i_rdev; |
| 613 | dest->i_atime = src->i_atime; |
| 614 | dest->i_mtime = src->i_mtime; |
| 615 | dest->i_ctime = src->i_ctime; |
| 616 | dest->i_blkbits = src->i_blkbits; |
| 617 | dest->i_flags = src->i_flags; |
| 618 | #ifdef CONFIG_FS_POSIX_ACL |
| 619 | dest->i_acl = src->i_acl; |
| 620 | #endif |
| 621 | #ifdef CONFIG_SECURITY |
| 622 | dest->i_security = src->i_security; |
| 623 | #endif |
| 624 | } |
| 625 | |
| 626 | static int sdcardfs_permission(struct vfsmount *mnt, struct inode *inode, int mask) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 627 | { |
| 628 | int err; |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 629 | struct inode tmp; |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 630 | struct sdcardfs_inode_data *top = top_data_get(SDCARDFS_I(inode)); |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 631 | |
Daniel Roseberg | 0df2f98 | 2017-05-09 13:36:35 -0700 | [diff] [blame] | 632 | if (!top) |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 633 | return -EINVAL; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 634 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 635 | /* |
| 636 | * Permission check on sdcardfs inode. |
| 637 | * Calling process should have AID_SDCARD_RW permission |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 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. |
| 641 | * |
| 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. |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 645 | */ |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 646 | copy_attrs(&tmp, inode); |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 647 | tmp.i_uid = make_kuid(&init_user_ns, top->d_uid); |
| 648 | tmp.i_gid = make_kgid(&init_user_ns, get_gid(mnt, top)); |
| 649 | tmp.i_mode = (inode->i_mode & S_IFMT) |
| 650 | | get_mode(mnt, SDCARDFS_I(inode), top); |
| 651 | data_put(top); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 652 | tmp.i_sb = inode->i_sb; |
| 653 | if (IS_POSIXACL(inode)) |
Daniel Rosenberg | 77ecf21 | 2017-03-16 17:46:13 -0700 | [diff] [blame] | 654 | pr_warn("%s: This may be undefined behavior...\n", __func__); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 655 | err = generic_permission(&tmp, mask); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 656 | /* XXX |
| 657 | * Original sdcardfs code calls inode_permission(lower_inode,.. ) |
| 658 | * for checking inode permission. But doing such things here seems |
| 659 | * duplicated work, because the functions called after this func, |
| 660 | * such as vfs_create, vfs_unlink, vfs_rename, and etc, |
| 661 | * does exactly same thing, i.e., they calls inode_permission(). |
| 662 | * So we just let they do the things. |
| 663 | * If there are any security hole, just uncomment following if block. |
| 664 | */ |
| 665 | #if 0 |
| 666 | if (!err) { |
| 667 | /* |
| 668 | * Permission check on lower_inode(=EXT4). |
| 669 | * we check it with AID_MEDIA_RW permission |
| 670 | */ |
| 671 | struct inode *lower_inode; |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 672 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 673 | OVERRIDE_CRED(SDCARDFS_SB(inode->sb)); |
| 674 | |
| 675 | lower_inode = sdcardfs_lower_inode(inode); |
| 676 | err = inode_permission(lower_inode, mask); |
| 677 | |
| 678 | REVERT_CRED(); |
| 679 | } |
| 680 | #endif |
| 681 | return err; |
| 682 | |
| 683 | } |
| 684 | |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 685 | static int sdcardfs_setattr_wrn(struct dentry *dentry, struct iattr *ia) |
| 686 | { |
Daniel Rosenberg | b434e57 | 2017-03-02 18:07:21 -0800 | [diff] [blame] | 687 | WARN_RATELIMIT(1, "sdcardfs does not support setattr. User setattr2.\n"); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 688 | return -EINVAL; |
| 689 | } |
| 690 | |
| 691 | static int sdcardfs_setattr(struct vfsmount *mnt, struct dentry *dentry, struct iattr *ia) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 692 | { |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 693 | int err; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 694 | struct dentry *lower_dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 695 | struct vfsmount *lower_mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 696 | struct inode *inode; |
| 697 | struct inode *lower_inode; |
| 698 | struct path lower_path; |
| 699 | struct iattr lower_ia; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 700 | struct dentry *parent; |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 701 | struct inode tmp; |
Amit Pundir | 82a2800 | 2016-10-11 13:26:17 +0530 | [diff] [blame] | 702 | struct dentry tmp_d; |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 703 | struct sdcardfs_inode_data *top; |
| 704 | |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 705 | const struct cred *saved_cred = NULL; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 706 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 707 | inode = d_inode(dentry); |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 708 | top = top_data_get(SDCARDFS_I(inode)); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 709 | |
Daniel Roseberg | 0df2f98 | 2017-05-09 13:36:35 -0700 | [diff] [blame] | 710 | if (!top) |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 711 | return -EINVAL; |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 712 | |
| 713 | /* |
| 714 | * Permission check on sdcardfs inode. |
| 715 | * Calling process should have AID_SDCARD_RW permission |
| 716 | * Since generic_permission only needs i_mode, i_uid, |
| 717 | * i_gid, and i_sb, we can create a fake inode to pass |
| 718 | * this information down in. |
| 719 | * |
| 720 | * The underlying code may attempt to take locks in some |
| 721 | * cases for features we're not using, but if that changes, |
| 722 | * locks must be dealt with to avoid undefined behavior. |
| 723 | * |
| 724 | */ |
| 725 | copy_attrs(&tmp, inode); |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 726 | tmp.i_uid = make_kuid(&init_user_ns, top->d_uid); |
| 727 | tmp.i_gid = make_kgid(&init_user_ns, get_gid(mnt, top)); |
| 728 | tmp.i_mode = (inode->i_mode & S_IFMT) |
| 729 | | get_mode(mnt, SDCARDFS_I(inode), top); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 730 | tmp.i_size = i_size_read(inode); |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 731 | data_put(top); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 732 | tmp.i_sb = inode->i_sb; |
Amit Pundir | 82a2800 | 2016-10-11 13:26:17 +0530 | [diff] [blame] | 733 | tmp_d.d_inode = &tmp; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 734 | |
| 735 | /* |
Amit Pundir | 82a2800 | 2016-10-11 13:26:17 +0530 | [diff] [blame] | 736 | * Check if user has permission to change dentry. We don't check if |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 737 | * this user can change the lower inode: that should happen when |
| 738 | * calling notify_change on the lower inode. |
| 739 | */ |
Daniel Rosenberg | 83d1cad | 2017-01-20 15:19:13 -0800 | [diff] [blame] | 740 | /* prepare our own lower struct iattr (with the lower file) */ |
| 741 | memcpy(&lower_ia, ia, sizeof(lower_ia)); |
| 742 | /* Allow touch updating timestamps. A previous permission check ensures |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 743 | * we have write access. Changes to mode, owner, and group are ignored |
| 744 | */ |
Daniel Rosenberg | 83d1cad | 2017-01-20 15:19:13 -0800 | [diff] [blame] | 745 | ia->ia_valid |= ATTR_FORCE; |
Amit Pundir | 82a2800 | 2016-10-11 13:26:17 +0530 | [diff] [blame] | 746 | err = setattr_prepare(&tmp_d, ia); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 747 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 748 | if (!err) { |
| 749 | /* check the Android group ID */ |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 750 | parent = dget_parent(dentry); |
Daniel Rosenberg | 32dc587 | 2017-03-10 18:58:25 -0800 | [diff] [blame] | 751 | if (!check_caller_access_to_name(d_inode(parent), &dentry->d_name)) |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 752 | err = -EACCES; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 753 | dput(parent); |
| 754 | } |
| 755 | |
| 756 | if (err) |
| 757 | goto out_err; |
| 758 | |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 759 | /* save current_cred and override it */ |
Daniel Rosenberg | ad90525 | 2017-01-25 13:48:45 -0800 | [diff] [blame] | 760 | OVERRIDE_CRED(SDCARDFS_SB(dentry->d_sb), saved_cred, SDCARDFS_I(inode)); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 761 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 762 | sdcardfs_get_lower_path(dentry, &lower_path); |
| 763 | lower_dentry = lower_path.dentry; |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 764 | lower_mnt = lower_path.mnt; |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 765 | lower_inode = sdcardfs_lower_inode(inode); |
| 766 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 767 | if (ia->ia_valid & ATTR_FILE) |
| 768 | lower_ia.ia_file = sdcardfs_lower_file(ia->ia_file); |
| 769 | |
| 770 | lower_ia.ia_valid &= ~(ATTR_UID | ATTR_GID | ATTR_MODE); |
| 771 | |
| 772 | /* |
| 773 | * If shrinking, first truncate upper level to cancel writing dirty |
| 774 | * pages beyond the new eof; and also if its' maxbytes is more |
| 775 | * limiting (fail with -EFBIG before making any change to the lower |
| 776 | * level). There is no need to vmtruncate the upper level |
| 777 | * afterwards in the other cases: we fsstack_copy_inode_size from |
| 778 | * the lower level. |
| 779 | */ |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 780 | if (ia->ia_valid & ATTR_SIZE) { |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 781 | err = inode_newsize_ok(&tmp, ia->ia_size); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 782 | if (err) { |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 783 | goto out; |
| 784 | } |
| 785 | truncate_setsize(inode, ia->ia_size); |
| 786 | } |
| 787 | |
| 788 | /* |
| 789 | * mode change is for clearing setuid/setgid bits. Allow lower fs |
| 790 | * to interpret this in its own way. |
| 791 | */ |
| 792 | if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
| 793 | lower_ia.ia_valid &= ~ATTR_MODE; |
| 794 | |
| 795 | /* notify the (possibly copied-up) lower inode */ |
| 796 | /* |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 797 | * Note: we use d_inode(lower_dentry), because lower_inode may be |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 798 | * unlinked (no inode->i_sb and i_ino==0. This happens if someone |
| 799 | * tries to open(), unlink(), then ftruncate() a file. |
| 800 | */ |
Amit Pundir | b47e110 | 2016-06-01 21:53:20 +0530 | [diff] [blame] | 801 | inode_lock(d_inode(lower_dentry)); |
Daniel Rosenberg | 1844d9e | 2016-10-26 16:48:45 -0700 | [diff] [blame] | 802 | err = notify_change2(lower_mnt, lower_dentry, &lower_ia, /* note: lower_ia */ |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 803 | NULL); |
Amit Pundir | b47e110 | 2016-06-01 21:53:20 +0530 | [diff] [blame] | 804 | inode_unlock(d_inode(lower_dentry)); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 805 | if (err) |
| 806 | goto out; |
| 807 | |
Daniel Rosenberg | 497ac90 | 2016-02-03 21:08:21 -0800 | [diff] [blame] | 808 | /* get attributes from the lower inode and update derived permissions */ |
| 809 | sdcardfs_copy_and_fix_attrs(inode, lower_inode); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 810 | |
| 811 | /* |
| 812 | * Not running fsstack_copy_inode_size(inode, lower_inode), because |
| 813 | * VFS should update our inode size, and notify_change on |
| 814 | * lower_inode should update its size. |
| 815 | */ |
| 816 | |
| 817 | out: |
| 818 | sdcardfs_put_lower_path(dentry, &lower_path); |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 819 | REVERT_CRED(saved_cred); |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 820 | out_err: |
| 821 | return err; |
| 822 | } |
| 823 | |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 824 | static int sdcardfs_fillattr(struct vfsmount *mnt, |
| 825 | struct inode *inode, struct kstat *stat) |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 826 | { |
| 827 | struct sdcardfs_inode_info *info = SDCARDFS_I(inode); |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 828 | struct sdcardfs_inode_data *top = top_data_get(info); |
Daniel Rosenberg | 5e024f6 | 2017-03-16 17:42:58 -0700 | [diff] [blame] | 829 | |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 830 | if (!top) |
| 831 | return -EINVAL; |
| 832 | |
| 833 | stat->dev = inode->i_sb->s_dev; |
| 834 | stat->ino = inode->i_ino; |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 835 | stat->mode = (inode->i_mode & S_IFMT) | get_mode(mnt, info, top); |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 836 | stat->nlink = inode->i_nlink; |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 837 | stat->uid = make_kuid(&init_user_ns, top->d_uid); |
| 838 | stat->gid = make_kgid(&init_user_ns, get_gid(mnt, top)); |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 839 | stat->rdev = inode->i_rdev; |
| 840 | stat->size = i_size_read(inode); |
| 841 | stat->atime = inode->i_atime; |
| 842 | stat->mtime = inode->i_mtime; |
| 843 | stat->ctime = inode->i_ctime; |
| 844 | stat->blksize = (1 << inode->i_blkbits); |
| 845 | stat->blocks = inode->i_blocks; |
Daniel Rosenberg | a56a105 | 2017-05-15 14:03:15 -0700 | [diff] [blame] | 846 | data_put(top); |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 847 | return 0; |
| 848 | } |
| 849 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 850 | static int sdcardfs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 851 | struct kstat *stat) |
| 852 | { |
Daniel Rosenberg | 3884c2e | 2017-03-09 18:12:16 -0800 | [diff] [blame] | 853 | struct kstat lower_stat; |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 854 | struct path lower_path; |
| 855 | struct dentry *parent; |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 856 | int err; |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 857 | |
| 858 | parent = dget_parent(dentry); |
Daniel Rosenberg | 5004c5f | 2017-01-31 20:07:51 -0800 | [diff] [blame] | 859 | if (!check_caller_access_to_name(d_inode(parent), &dentry->d_name)) { |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 860 | dput(parent); |
| 861 | return -EACCES; |
| 862 | } |
| 863 | dput(parent); |
| 864 | |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 865 | sdcardfs_get_lower_path(dentry, &lower_path); |
Daniel Rosenberg | 3884c2e | 2017-03-09 18:12:16 -0800 | [diff] [blame] | 866 | err = vfs_getattr(&lower_path, &lower_stat); |
| 867 | if (err) |
| 868 | goto out; |
| 869 | sdcardfs_copy_and_fix_attrs(d_inode(dentry), |
| 870 | d_inode(lower_path.dentry)); |
| 871 | err = sdcardfs_fillattr(mnt, d_inode(dentry), stat); |
| 872 | stat->blocks = lower_stat.blocks; |
| 873 | out: |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 874 | sdcardfs_put_lower_path(dentry, &lower_path); |
Daniel Rosenberg | 5080d24 | 2016-05-18 16:57:10 -0700 | [diff] [blame] | 875 | return err; |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 878 | const struct inode_operations sdcardfs_symlink_iops = { |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 879 | .permission2 = sdcardfs_permission, |
| 880 | .setattr2 = sdcardfs_setattr, |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 881 | /* XXX Following operations are implemented, |
| 882 | * but FUSE(sdcard) or FAT does not support them |
| 883 | * These methods are *NOT* perfectly tested. |
| 884 | .readlink = sdcardfs_readlink, |
| 885 | .follow_link = sdcardfs_follow_link, |
Daniel Campello | d1d080c | 2015-07-20 16:27:37 -0700 | [diff] [blame] | 886 | .put_link = kfree_put_link, |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 887 | */ |
| 888 | }; |
| 889 | |
| 890 | const struct inode_operations sdcardfs_dir_iops = { |
| 891 | .create = sdcardfs_create, |
| 892 | .lookup = sdcardfs_lookup, |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 893 | .permission = sdcardfs_permission_wrn, |
| 894 | .permission2 = sdcardfs_permission, |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 895 | .unlink = sdcardfs_unlink, |
| 896 | .mkdir = sdcardfs_mkdir, |
| 897 | .rmdir = sdcardfs_rmdir, |
| 898 | .rename = sdcardfs_rename, |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 899 | .setattr = sdcardfs_setattr_wrn, |
| 900 | .setattr2 = sdcardfs_setattr, |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 901 | .getattr = sdcardfs_getattr, |
| 902 | /* XXX Following operations are implemented, |
| 903 | * but FUSE(sdcard) or FAT does not support them |
| 904 | * These methods are *NOT* perfectly tested. |
| 905 | .symlink = sdcardfs_symlink, |
| 906 | .link = sdcardfs_link, |
| 907 | .mknod = sdcardfs_mknod, |
| 908 | */ |
| 909 | }; |
| 910 | |
| 911 | const struct inode_operations sdcardfs_main_iops = { |
Daniel Rosenberg | 9021927 | 2016-10-26 20:27:20 -0700 | [diff] [blame] | 912 | .permission = sdcardfs_permission_wrn, |
| 913 | .permission2 = sdcardfs_permission, |
| 914 | .setattr = sdcardfs_setattr_wrn, |
| 915 | .setattr2 = sdcardfs_setattr, |
Daniel Campello | 35c9e24 | 2015-07-20 16:23:50 -0700 | [diff] [blame] | 916 | .getattr = sdcardfs_getattr, |
| 917 | }; |