]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
new primitive: vfs_mkobj()
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 1 Dec 2017 22:12:45 +0000 (17:12 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 5 Jan 2018 16:53:07 +0000 (11:53 -0500)
Similar to vfs_create(), but with caller-supplied callback (and
argument for it) to be used instead of ->create().

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namei.c
include/linux/fs.h

index 9cc91fb7f156541bd53243b35c2823bbf9ca1133..1c0fb97c94251ef80084542d98b214c1a79da51e 100644 (file)
@@ -2898,6 +2898,27 @@ int vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
 }
 EXPORT_SYMBOL(vfs_create);
 
+int vfs_mkobj(struct dentry *dentry, umode_t mode,
+               int (*f)(struct dentry *, umode_t, void *),
+               void *arg)
+{
+       struct inode *dir = dentry->d_parent->d_inode;
+       int error = may_create(dir, dentry);
+       if (error)
+               return error;
+
+       mode &= S_IALLUGO;
+       mode |= S_IFREG;
+       error = security_inode_create(dir, dentry, mode);
+       if (error)
+               return error;
+       error = f(dentry, mode, arg);
+       if (!error)
+               fsnotify_create(dir, dentry);
+       return error;
+}
+EXPORT_SYMBOL(vfs_mkobj);
+
 bool may_open_dev(const struct path *path)
 {
        return !(path->mnt->mnt_flags & MNT_NODEV) &&
index 511fbaabf6248b67220c16653e491f74e3f046e7..aad23d4fae47fc1de917f405606aafae3b80c906 100644 (file)
@@ -1608,6 +1608,10 @@ extern int vfs_whiteout(struct inode *, struct dentry *);
 extern struct dentry *vfs_tmpfile(struct dentry *dentry, umode_t mode,
                                  int open_flag);
 
+int vfs_mkobj(struct dentry *, umode_t,
+               int (*f)(struct dentry *, umode_t, void *),
+               void *);
+
 /*
  * VFS file helper functions.
  */