fs: add a vfs_fchown helper
[ Upstream commit c04011fe8cbd80af1be6e12b53193bf3846750d7 ]
Add a helper for struct file based chown operations. To be used by
the initramfs code soon.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Stable-dep-of: 4624b346cf67 ("init: open /initrd.image with O_LARGEFILE")
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
9550632ba9
commit
8eba8d1145
2 changed files with 19 additions and 12 deletions
29
fs/open.c
29
fs/open.c
|
|
@ -708,23 +708,28 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
|
||||||
AT_SYMLINK_NOFOLLOW);
|
AT_SYMLINK_NOFOLLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vfs_fchown(struct file *file, uid_t user, gid_t group)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
|
||||||
|
error = mnt_want_write_file(file);
|
||||||
|
if (error)
|
||||||
|
return error;
|
||||||
|
audit_file(file);
|
||||||
|
error = chown_common(&file->f_path, user, group);
|
||||||
|
mnt_drop_write_file(file);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
|
int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int error = -EBADF;
|
int error = -EBADF;
|
||||||
|
|
||||||
if (!f.file)
|
if (f.file) {
|
||||||
goto out;
|
error = vfs_fchown(f.file, user, group);
|
||||||
|
fdput(f);
|
||||||
error = mnt_want_write_file(f.file);
|
}
|
||||||
if (error)
|
|
||||||
goto out_fput;
|
|
||||||
audit_file(f.file);
|
|
||||||
error = chown_common(&f.file->f_path, user, group);
|
|
||||||
mnt_drop_write_file(f.file);
|
|
||||||
out_fput:
|
|
||||||
fdput(f);
|
|
||||||
out:
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1730,6 +1730,8 @@ int vfs_mkobj(struct dentry *, umode_t,
|
||||||
int (*f)(struct dentry *, umode_t, void *),
|
int (*f)(struct dentry *, umode_t, void *),
|
||||||
void *);
|
void *);
|
||||||
|
|
||||||
|
int vfs_fchown(struct file *file, uid_t user, gid_t group);
|
||||||
|
|
||||||
extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
|
extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
|
||||||
|
|
||||||
#ifdef CONFIG_COMPAT
|
#ifdef CONFIG_COMPAT
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue