new primitive: vfs_mkobj()

Similar to vfs_create(), but with caller-supplied callback (and
argument for it) to be used instead of ->create().

Change-Id: Ie67e2af6fb43bf75d316105e6eb5c14fc3663dd4
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro
2017-12-01 17:12:45 -05:00
committed by theshaenix
parent f841a6f77a
commit 2fc3252bc1
2 changed files with 25 additions and 0 deletions

View File

@@ -3052,6 +3052,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(NULL, 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) &&

View File

@@ -1656,6 +1656,10 @@ extern struct dentry *vfs_tmpfile(struct vfsmount *mnt,
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.
*/