ANDROID: sdcardfs: User new permission2 functions

Change-Id: Ic7e0fb8fdcebb31e657b079fe02ac834c4a50db9
Signed-off-by: Daniel Rosenberg <drosen@google.com>
This commit is contained in:
Daniel Rosenberg 2016-10-26 16:48:45 -07:00
parent 1cbf8e31e3
commit f9cb61dcb0
2 changed files with 21 additions and 8 deletions

View file

@ -54,6 +54,7 @@ static int sdcardfs_create(struct inode *dir, struct dentry *dentry,
{ {
int err; int err;
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct vfsmount *lower_dentry_mnt;
struct dentry *lower_parent_dentry = NULL; struct dentry *lower_parent_dentry = NULL;
struct path lower_path; struct path lower_path;
const struct cred *saved_cred = NULL; const struct cred *saved_cred = NULL;
@ -73,6 +74,7 @@ static int sdcardfs_create(struct inode *dir, struct dentry *dentry,
sdcardfs_get_lower_path(dentry, &lower_path); sdcardfs_get_lower_path(dentry, &lower_path);
lower_dentry = lower_path.dentry; lower_dentry = lower_path.dentry;
lower_dentry_mnt = lower_path.mnt;
lower_parent_dentry = lock_parent(lower_dentry); lower_parent_dentry = lock_parent(lower_dentry);
/* set last 16bytes of mode field to 0664 */ /* set last 16bytes of mode field to 0664 */
@ -87,7 +89,7 @@ static int sdcardfs_create(struct inode *dir, struct dentry *dentry,
} }
current->fs = copied_fs; current->fs = copied_fs;
current->fs->umask = 0; current->fs->umask = 0;
err = vfs_create(d_inode(lower_parent_dentry), lower_dentry, mode, want_excl); err = vfs_create2(lower_dentry_mnt, d_inode(lower_parent_dentry), lower_dentry, mode, want_excl);
if (err) if (err)
goto out; goto out;
@ -154,6 +156,7 @@ static int sdcardfs_unlink(struct inode *dir, struct dentry *dentry)
{ {
int err; int err;
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct vfsmount *lower_mnt;
struct inode *lower_dir_inode = sdcardfs_lower_inode(dir); struct inode *lower_dir_inode = sdcardfs_lower_inode(dir);
struct dentry *lower_dir_dentry; struct dentry *lower_dir_dentry;
struct path lower_path; struct path lower_path;
@ -172,10 +175,11 @@ static int sdcardfs_unlink(struct inode *dir, struct dentry *dentry)
sdcardfs_get_lower_path(dentry, &lower_path); sdcardfs_get_lower_path(dentry, &lower_path);
lower_dentry = lower_path.dentry; lower_dentry = lower_path.dentry;
lower_mnt = lower_path.mnt;
dget(lower_dentry); dget(lower_dentry);
lower_dir_dentry = lock_parent(lower_dentry); lower_dir_dentry = lock_parent(lower_dentry);
err = vfs_unlink(lower_dir_inode, lower_dentry, NULL); err = vfs_unlink2(lower_mnt, lower_dir_inode, lower_dentry, NULL);
/* /*
* Note: unlinking on top of NFS can cause silly-renamed files. * Note: unlinking on top of NFS can cause silly-renamed files.
@ -256,6 +260,7 @@ static int sdcardfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
int err; int err;
int make_nomedia_in_obb = 0; int make_nomedia_in_obb = 0;
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct vfsmount *lower_mnt;
struct dentry *lower_parent_dentry = NULL; struct dentry *lower_parent_dentry = NULL;
struct path lower_path; struct path lower_path;
struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb); struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
@ -286,6 +291,7 @@ static int sdcardfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
/* the lower_dentry is negative here */ /* the lower_dentry is negative here */
sdcardfs_get_lower_path(dentry, &lower_path); sdcardfs_get_lower_path(dentry, &lower_path);
lower_dentry = lower_path.dentry; lower_dentry = lower_path.dentry;
lower_mnt = lower_path.mnt;
lower_parent_dentry = lock_parent(lower_dentry); lower_parent_dentry = lock_parent(lower_dentry);
/* set last 16bytes of mode field to 0775 */ /* set last 16bytes of mode field to 0775 */
@ -301,7 +307,7 @@ static int sdcardfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
} }
current->fs = copied_fs; current->fs = copied_fs;
current->fs->umask = 0; current->fs->umask = 0;
err = vfs_mkdir(d_inode(lower_parent_dentry), lower_dentry, mode); err = vfs_mkdir2(lower_mnt, d_inode(lower_parent_dentry), lower_dentry, mode);
if (err) { if (err) {
unlock_dir(lower_parent_dentry); unlock_dir(lower_parent_dentry);
@ -370,6 +376,7 @@ static int sdcardfs_rmdir(struct inode *dir, struct dentry *dentry)
{ {
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct dentry *lower_dir_dentry; struct dentry *lower_dir_dentry;
struct vfsmount *lower_mnt;
int err; int err;
struct path lower_path; struct path lower_path;
const struct cred *saved_cred = NULL; const struct cred *saved_cred = NULL;
@ -390,9 +397,10 @@ static int sdcardfs_rmdir(struct inode *dir, struct dentry *dentry)
sdcardfs_get_real_lower(dentry, &lower_path); sdcardfs_get_real_lower(dentry, &lower_path);
lower_dentry = lower_path.dentry; lower_dentry = lower_path.dentry;
lower_mnt = lower_path.mnt;
lower_dir_dentry = lock_parent(lower_dentry); lower_dir_dentry = lock_parent(lower_dentry);
err = vfs_rmdir(d_inode(lower_dir_dentry), lower_dentry); err = vfs_rmdir2(lower_mnt, d_inode(lower_dir_dentry), lower_dentry);
if (err) if (err)
goto out; goto out;
@ -456,6 +464,7 @@ static int sdcardfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct dentry *lower_new_dentry = NULL; struct dentry *lower_new_dentry = NULL;
struct dentry *lower_old_dir_dentry = NULL; struct dentry *lower_old_dir_dentry = NULL;
struct dentry *lower_new_dir_dentry = NULL; struct dentry *lower_new_dir_dentry = NULL;
struct vfsmount *lower_mnt = NULL;
struct dentry *trap = NULL; struct dentry *trap = NULL;
struct dentry *new_parent = NULL; struct dentry *new_parent = NULL;
struct path lower_old_path, lower_new_path; struct path lower_old_path, lower_new_path;
@ -477,6 +486,7 @@ static int sdcardfs_rename(struct inode *old_dir, struct dentry *old_dentry,
sdcardfs_get_lower_path(new_dentry, &lower_new_path); sdcardfs_get_lower_path(new_dentry, &lower_new_path);
lower_old_dentry = lower_old_path.dentry; lower_old_dentry = lower_old_path.dentry;
lower_new_dentry = lower_new_path.dentry; lower_new_dentry = lower_new_path.dentry;
lower_mnt = lower_old_path.mnt;
lower_old_dir_dentry = dget_parent(lower_old_dentry); lower_old_dir_dentry = dget_parent(lower_old_dentry);
lower_new_dir_dentry = dget_parent(lower_new_dentry); lower_new_dir_dentry = dget_parent(lower_new_dentry);
@ -492,7 +502,8 @@ static int sdcardfs_rename(struct inode *old_dir, struct dentry *old_dentry,
goto out; goto out;
} }
err = vfs_rename(d_inode(lower_old_dir_dentry), lower_old_dentry, err = vfs_rename2(lower_mnt,
d_inode(lower_old_dir_dentry), lower_old_dentry,
d_inode(lower_new_dir_dentry), lower_new_dentry, d_inode(lower_new_dir_dentry), lower_new_dentry,
NULL, 0); NULL, 0);
if (err) if (err)
@ -642,6 +653,7 @@ static int sdcardfs_setattr(struct dentry *dentry, struct iattr *ia)
{ {
int err; int err;
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct vfsmount *lower_mnt;
struct inode *inode; struct inode *inode;
struct inode *lower_inode; struct inode *lower_inode;
struct path lower_path; struct path lower_path;
@ -675,6 +687,7 @@ static int sdcardfs_setattr(struct dentry *dentry, struct iattr *ia)
sdcardfs_get_lower_path(dentry, &lower_path); sdcardfs_get_lower_path(dentry, &lower_path);
lower_dentry = lower_path.dentry; lower_dentry = lower_path.dentry;
lower_mnt = lower_path.mnt;
lower_inode = sdcardfs_lower_inode(inode); lower_inode = sdcardfs_lower_inode(inode);
/* prepare our own lower struct iattr (with the lower file) */ /* prepare our own lower struct iattr (with the lower file) */
@ -718,7 +731,7 @@ static int sdcardfs_setattr(struct dentry *dentry, struct iattr *ia)
* tries to open(), unlink(), then ftruncate() a file. * tries to open(), unlink(), then ftruncate() a file.
*/ */
mutex_lock(&d_inode(lower_dentry)->i_mutex); mutex_lock(&d_inode(lower_dentry)->i_mutex);
err = notify_change(lower_dentry, &lower_ia, /* note: lower_ia */ err = notify_change2(lower_mnt, lower_dentry, &lower_ia, /* note: lower_ia */
NULL); NULL);
mutex_unlock(&d_inode(lower_dentry)->i_mutex); mutex_unlock(&d_inode(lower_dentry)->i_mutex);
if (current->mm) if (current->mm)

View file

@ -476,7 +476,7 @@ static inline int prepare_dir(const char *path_s, uid_t uid, gid_t gid, mode_t m
goto out_unlock; goto out_unlock;
} }
err = vfs_mkdir(d_inode(parent.dentry), dent, mode); err = vfs_mkdir2(parent.mnt, d_inode(parent.dentry), dent, mode);
if (err) { if (err) {
if (err == -EEXIST) if (err == -EEXIST)
err = 0; err = 0;
@ -487,7 +487,7 @@ static inline int prepare_dir(const char *path_s, uid_t uid, gid_t gid, mode_t m
attrs.ia_gid = make_kgid(&init_user_ns, gid); attrs.ia_gid = make_kgid(&init_user_ns, gid);
attrs.ia_valid = ATTR_UID | ATTR_GID; attrs.ia_valid = ATTR_UID | ATTR_GID;
mutex_lock(&d_inode(dent)->i_mutex); mutex_lock(&d_inode(dent)->i_mutex);
notify_change(dent, &attrs, NULL); notify_change2(parent.mnt, dent, &attrs, NULL);
mutex_unlock(&d_inode(dent)->i_mutex); mutex_unlock(&d_inode(dent)->i_mutex);
out_dput: out_dput: