Files
ubports_kernel_google_msm/fs/open.c.rej

152 lines
4.2 KiB
Plaintext

--- fs/open.c
+++ fs/open.c
@@ -644,24 +644,24 @@ static inline int __get_file_write_access(struct inode *inode,
return error;
}
-static struct file *__dentry_open(struct path *path, struct file *f,
- int (*open)(struct inode *, struct file *),
- const struct cred *cred)
+static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
+ struct file *f,
+ int (*open)(struct inode *, struct file *),
+ const struct cred *cred)
{
static const struct file_operations empty_fops = {};
struct inode *inode;
int error;
- path_get(path);
f->f_mode = OPEN_FMODE(f->f_flags) | FMODE_LSEEK |
FMODE_PREAD | FMODE_PWRITE;
if (unlikely(f->f_flags & O_PATH))
f->f_mode = FMODE_PATH;
- inode = path->dentry->d_inode;
+ inode = dentry->d_inode;
if (f->f_mode & FMODE_WRITE) {
- error = __get_file_write_access(inode, path->mnt);
+ error = __get_file_write_access(inode, mnt);
if (error)
goto cleanup_file;
if (!special_file(inode->i_mode))
@@ -669,7 +669,8 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
}
f->f_mapping = inode->i_mapping;
- f->f_path = *path;
+ f->f_path.dentry = dentry;
+ f->f_path.mnt = mnt;
f->f_pos = 0;
file_sb_list_add(f, inode->i_sb);
@@ -726,7 +727,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
* here, so just reset the state.
*/
file_reset_write(f);
- mnt_drop_write(path->mnt);
+ mnt_drop_write(mnt);
}
}
file_sb_list_del(f);
@@ -734,7 +735,8 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
f->f_path.mnt = NULL;
cleanup_file:
put_filp(f);
- path_put(path);
+ dput(dentry);
+ mntput(mnt);
return ERR_PTR(error);
}
@@ -760,14 +762,14 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
struct file *lookup_instantiate_filp(struct nameidata *nd, struct dentry *dentry,
int (*open)(struct inode *, struct file *))
{
- struct path path = { .dentry = dentry, .mnt = nd->path.mnt };
const struct cred *cred = current_cred();
if (IS_ERR(nd->intent.open.file))
goto out;
if (IS_ERR(dentry))
goto out_err;
- nd->intent.open.file = __dentry_open(&path, nd->intent.open.file,
+ nd->intent.open.file = __dentry_open(dget(dentry), mntget(nd->path.mnt),
+ nd->intent.open.file,
open, cred);
out:
return nd->intent.open.file;
@@ -795,9 +797,11 @@ struct file *nameidata_to_filp(struct nameidata *nd)
nd->intent.open.file = NULL;
/* Has the filesystem initialised the file for us? */
- if (filp->f_path.dentry == NULL)
- filp = vfs_open(&nd->path, filp, cred);
-
+ if (filp->f_path.dentry == NULL) {
+ path_get(&nd->path);
+ filp = __dentry_open(nd->path.dentry, nd->path.mnt, filp,
+ NULL, cred);
+ }
return filp;
}
@@ -808,48 +812,27 @@ struct file *nameidata_to_filp(struct nameidata *nd)
struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags,
const struct cred *cred)
{
+ int error;
struct file *f;
- struct file *ret;
- struct path path = { .dentry = dentry, .mnt = mnt };
validate_creds(cred);
/* We must always pass in a valid mount pointer. */
BUG_ON(!mnt);
- ret = ERR_PTR(-ENFILE);
+ error = -ENFILE;
f = get_empty_filp();
- if (f != NULL) {
- f->f_flags = flags;
- ret = vfs_open(&path, f, cred);
+ if (f == NULL) {
+ dput(dentry);
+ mntput(mnt);
+ return ERR_PTR(error);
}
- path_put(&path);
- return ret;
+ f->f_flags = flags;
+ return __dentry_open(dentry, mnt, f, NULL, cred);
}
EXPORT_SYMBOL(dentry_open);
-/**
- * vfs_open - open the file at the given path
- * @path: path to open
- * @filp: newly allocated file with f_flag initialized
- * @cred: credentials to use
- *
- * Open the file. If successful, the returned file will have acquired
- * an additional reference for path.
- */
-struct file *vfs_open(struct path *path, struct file *filp,
- const struct cred *cred)
-{
- struct inode *inode = path->dentry->d_inode;
-
- if (inode->i_op->open)
- return inode->i_op->open(path->dentry, filp, cred);
- else
- return __dentry_open(path, filp, NULL, cred);
-}
-EXPORT_SYMBOL(vfs_open);
-
static void __put_unused_fd(struct files_struct *files, unsigned int fd)
{
struct fdtable *fdt = files_fdtable(files);