Separate out common fstatat code into vfs_fstatat
This is a version incorporating Christoph's suggestion. Separate out common *fstatat functionality into a single function instead of duplicating it all over the code. Signed-off-by: Oleg Drokin <green@linuxhacker.ru> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
fd56d242b3
commit
0112fc2229
|
@ -177,21 +177,12 @@ asmlinkage long sys_oabi_fstatat64(int dfd,
|
||||||
int flag)
|
int flag)
|
||||||
{
|
{
|
||||||
struct kstat stat;
|
struct kstat stat;
|
||||||
int error = -EINVAL;
|
int error;
|
||||||
|
|
||||||
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
error = vfs_fstatat(dfd, filename, &stat, flag);
|
||||||
goto out;
|
if (error)
|
||||||
|
return error;
|
||||||
if (flag & AT_SYMLINK_NOFOLLOW)
|
return cp_oldabi_stat64(&stat, statbuf);
|
||||||
error = vfs_lstat_fd(dfd, filename, &stat);
|
|
||||||
else
|
|
||||||
error = vfs_stat_fd(dfd, filename, &stat);
|
|
||||||
|
|
||||||
if (!error)
|
|
||||||
error = cp_oldabi_stat64(&stat, statbuf);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct oabi_flock64 {
|
struct oabi_flock64 {
|
||||||
|
|
|
@ -702,20 +702,12 @@ asmlinkage long sys32_fstatat64(unsigned int dfd, char __user *filename,
|
||||||
struct stat64_emu31 __user* statbuf, int flag)
|
struct stat64_emu31 __user* statbuf, int flag)
|
||||||
{
|
{
|
||||||
struct kstat stat;
|
struct kstat stat;
|
||||||
int error = -EINVAL;
|
int error;
|
||||||
|
|
||||||
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
error = vfs_fstatat(dfd, filename, &stat, flag);
|
||||||
goto out;
|
if (error)
|
||||||
|
return error;
|
||||||
if (flag & AT_SYMLINK_NOFOLLOW)
|
return cp_stat64(statbuf, &stat);
|
||||||
error = vfs_lstat_fd(dfd, filename, &stat);
|
|
||||||
else
|
|
||||||
error = vfs_stat_fd(dfd, filename, &stat);
|
|
||||||
|
|
||||||
if (!error)
|
|
||||||
error = cp_stat64(statbuf, &stat);
|
|
||||||
out:
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -206,21 +206,12 @@ asmlinkage long compat_sys_fstatat64(unsigned int dfd, char __user *filename,
|
||||||
struct compat_stat64 __user * statbuf, int flag)
|
struct compat_stat64 __user * statbuf, int flag)
|
||||||
{
|
{
|
||||||
struct kstat stat;
|
struct kstat stat;
|
||||||
int error = -EINVAL;
|
int error;
|
||||||
|
|
||||||
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
error = vfs_fstatat(dfd, filename, &stat, flag);
|
||||||
goto out;
|
if (error)
|
||||||
|
return error;
|
||||||
if (flag & AT_SYMLINK_NOFOLLOW)
|
return cp_compat_stat64(&stat, statbuf);
|
||||||
error = vfs_lstat_fd(dfd, filename, &stat);
|
|
||||||
else
|
|
||||||
error = vfs_stat_fd(dfd, filename, &stat);
|
|
||||||
|
|
||||||
if (!error)
|
|
||||||
error = cp_compat_stat64(&stat, statbuf);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
|
asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
|
||||||
|
|
|
@ -129,21 +129,12 @@ asmlinkage long sys32_fstatat(unsigned int dfd, char __user *filename,
|
||||||
struct stat64 __user *statbuf, int flag)
|
struct stat64 __user *statbuf, int flag)
|
||||||
{
|
{
|
||||||
struct kstat stat;
|
struct kstat stat;
|
||||||
int error = -EINVAL;
|
int error;
|
||||||
|
|
||||||
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
error = vfs_fstatat(dfd, filename, &stat, flag);
|
||||||
goto out;
|
if (error)
|
||||||
|
return error;
|
||||||
if (flag & AT_SYMLINK_NOFOLLOW)
|
return cp_stat64(statbuf, &stat);
|
||||||
error = vfs_lstat_fd(dfd, filename, &stat);
|
|
||||||
else
|
|
||||||
error = vfs_stat_fd(dfd, filename, &stat);
|
|
||||||
|
|
||||||
if (!error)
|
|
||||||
error = cp_stat64(statbuf, &stat);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
19
fs/compat.c
19
fs/compat.c
|
@ -204,21 +204,12 @@ asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user *filename,
|
||||||
struct compat_stat __user *statbuf, int flag)
|
struct compat_stat __user *statbuf, int flag)
|
||||||
{
|
{
|
||||||
struct kstat stat;
|
struct kstat stat;
|
||||||
int error = -EINVAL;
|
int error;
|
||||||
|
|
||||||
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
error = vfs_fstatat(dfd, filename, &stat, flag);
|
||||||
goto out;
|
if (error)
|
||||||
|
return error;
|
||||||
if (flag & AT_SYMLINK_NOFOLLOW)
|
return cp_compat_stat(&stat, statbuf);
|
||||||
error = vfs_lstat_fd(dfd, filename, &stat);
|
|
||||||
else
|
|
||||||
error = vfs_stat_fd(dfd, filename, &stat);
|
|
||||||
|
|
||||||
if (!error)
|
|
||||||
error = cp_compat_stat(&stat, statbuf);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
56
fs/stat.c
56
fs/stat.c
|
@ -109,6 +109,24 @@ int vfs_fstat(unsigned int fd, struct kstat *stat)
|
||||||
|
|
||||||
EXPORT_SYMBOL(vfs_fstat);
|
EXPORT_SYMBOL(vfs_fstat);
|
||||||
|
|
||||||
|
int vfs_fstatat(int dfd, char __user *filename, struct kstat *stat, int flag)
|
||||||
|
{
|
||||||
|
int error = -EINVAL;
|
||||||
|
|
||||||
|
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (flag & AT_SYMLINK_NOFOLLOW)
|
||||||
|
error = vfs_lstat_fd(dfd, filename, stat);
|
||||||
|
else
|
||||||
|
error = vfs_stat_fd(dfd, filename, stat);
|
||||||
|
out:
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT_SYMBOL(vfs_fstatat);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __ARCH_WANT_OLD_STAT
|
#ifdef __ARCH_WANT_OLD_STAT
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -264,21 +282,12 @@ SYSCALL_DEFINE4(newfstatat, int, dfd, char __user *, filename,
|
||||||
struct stat __user *, statbuf, int, flag)
|
struct stat __user *, statbuf, int, flag)
|
||||||
{
|
{
|
||||||
struct kstat stat;
|
struct kstat stat;
|
||||||
int error = -EINVAL;
|
int error;
|
||||||
|
|
||||||
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
error = vfs_fstatat(dfd, filename, &stat, flag);
|
||||||
goto out;
|
if (error)
|
||||||
|
return error;
|
||||||
if (flag & AT_SYMLINK_NOFOLLOW)
|
return cp_new_stat(&stat, statbuf);
|
||||||
error = vfs_lstat_fd(dfd, filename, &stat);
|
|
||||||
else
|
|
||||||
error = vfs_stat_fd(dfd, filename, &stat);
|
|
||||||
|
|
||||||
if (!error)
|
|
||||||
error = cp_new_stat(&stat, statbuf);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -404,21 +413,12 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, char __user *, filename,
|
||||||
struct stat64 __user *, statbuf, int, flag)
|
struct stat64 __user *, statbuf, int, flag)
|
||||||
{
|
{
|
||||||
struct kstat stat;
|
struct kstat stat;
|
||||||
int error = -EINVAL;
|
int error;
|
||||||
|
|
||||||
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
error = vfs_fstatat(dfd, filename, &stat, flag);
|
||||||
goto out;
|
if (error)
|
||||||
|
return error;
|
||||||
if (flag & AT_SYMLINK_NOFOLLOW)
|
return cp_new_stat64(&stat, statbuf);
|
||||||
error = vfs_lstat_fd(dfd, filename, &stat);
|
|
||||||
else
|
|
||||||
error = vfs_stat_fd(dfd, filename, &stat);
|
|
||||||
|
|
||||||
if (!error)
|
|
||||||
error = cp_new_stat64(&stat, statbuf);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
#endif /* __ARCH_WANT_STAT64 */
|
#endif /* __ARCH_WANT_STAT64 */
|
||||||
|
|
||||||
|
|
|
@ -2302,6 +2302,7 @@ extern int vfs_lstat(char __user *, struct kstat *);
|
||||||
extern int vfs_stat_fd(int dfd, char __user *, struct kstat *);
|
extern int vfs_stat_fd(int dfd, char __user *, struct kstat *);
|
||||||
extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *);
|
extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *);
|
||||||
extern int vfs_fstat(unsigned int, struct kstat *);
|
extern int vfs_fstat(unsigned int, struct kstat *);
|
||||||
|
extern int vfs_fstatat(int , char __user *, struct kstat *, int);
|
||||||
|
|
||||||
extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
|
extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
|
||||||
unsigned long arg);
|
unsigned long arg);
|
||||||
|
|
Loading…
Reference in New Issue