+ * Lookup, maybe create and open the last component
+ *
+ * Must be called with i_mutex held on parent.
+ *
+ * Returns open file or NULL on success, error otherwise. NULL means no open
+ * was performed, only lookup.
+ */
+static struct file *lookup_open(struct nameidata *nd, struct path *path,
+ const struct open_flags *op,
+ int *want_write, bool *created)
+{
+ struct dentry *dir = nd->path.dentry;
+ struct dentry *dentry;
+ int error;
+
+ *created = false;
+ dentry = lookup_hash(nd);
+ if (IS_ERR(dentry))
+ return ERR_CAST(dentry);
+
+ /* Negative dentry, just create the file */
+ if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
+ umode_t mode = op->mode;
+ if (!IS_POSIXACL(dir->d_inode))
+ mode &= ~current_umask();
+ /*
+ * This write is needed to ensure that a
+ * rw->ro transition does not occur between
+ * the time when the file is created and when
+ * a permanent write count is taken through
+ * the 'struct file' in nameidata_to_filp().
+ */
+ error = mnt_want_write(nd->path.mnt);
+ if (error)
+ goto out_dput;
+ *want_write = 1;
+ *created = true;
+ error = security_path_mknod(&nd->path, dentry, mode, 0);
+ if (error)
+ goto out_dput;
+ error = vfs_create(dir->d_inode, dentry, mode, nd);
+ if (error)
+ goto out_dput;
+ }
+ path->dentry = dentry;
+ path->mnt = nd->path.mnt;
+ return NULL;
+
+out_dput:
+ dput(dentry);
+ return ERR_PTR(error);
+}
+
+/*