Skip to content

Commit

Permalink
Separate out common fstatat code into vfs_fstatat
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
verygreen authored and Al Viro committed Apr 21, 2009
1 parent fd56d24 commit 0112fc2
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 97 deletions.
19 changes: 5 additions & 14 deletions arch/arm/kernel/sys_oabi-compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,12 @@ asmlinkage long sys_oabi_fstatat64(int dfd,
int flag)
{
struct kstat stat;
int error = -EINVAL;
int error;

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);

if (!error)
error = cp_oldabi_stat64(&stat, statbuf);

out:
return error;
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
return cp_oldabi_stat64(&stat, statbuf);
}

struct oabi_flock64 {
Expand Down
18 changes: 5 additions & 13 deletions arch/s390/kernel/compat_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,20 +702,12 @@ asmlinkage long sys32_fstatat64(unsigned int dfd, char __user *filename,
struct stat64_emu31 __user* statbuf, int flag)
{
struct kstat stat;
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);
int error;

if (!error)
error = cp_stat64(statbuf, &stat);
out:
return error;
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
return cp_stat64(statbuf, &stat);
}

/*
Expand Down
19 changes: 5 additions & 14 deletions arch/sparc/kernel/sys_sparc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,12 @@ asmlinkage long compat_sys_fstatat64(unsigned int dfd, char __user *filename,
struct compat_stat64 __user * statbuf, int flag)
{
struct kstat stat;
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);

if (!error)
error = cp_compat_stat64(&stat, statbuf);
int error;

out:
return error;
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
return cp_compat_stat64(&stat, statbuf);
}

asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
Expand Down
19 changes: 5 additions & 14 deletions arch/x86/ia32/sys_ia32.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,12 @@ asmlinkage long sys32_fstatat(unsigned int dfd, char __user *filename,
struct stat64 __user *statbuf, int flag)
{
struct kstat stat;
int error = -EINVAL;
int error;

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);

if (!error)
error = cp_stat64(statbuf, &stat);

out:
return error;
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
return cp_stat64(statbuf, &stat);
}

/*
Expand Down
19 changes: 5 additions & 14 deletions fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,12 @@ asmlinkage long compat_sys_newfstatat(unsigned int dfd, char __user *filename,
struct compat_stat __user *statbuf, int flag)
{
struct kstat stat;
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);

if (!error)
error = cp_compat_stat(&stat, statbuf);
int error;

out:
return error;
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
return cp_compat_stat(&stat, statbuf);
}
#endif

Expand Down
56 changes: 28 additions & 28 deletions fs/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ int vfs_fstat(unsigned int fd, struct kstat *stat)

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

/*
Expand Down Expand Up @@ -264,21 +282,12 @@ SYSCALL_DEFINE4(newfstatat, int, dfd, char __user *, filename,
struct stat __user *, statbuf, int, flag)
{
struct kstat stat;
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);

if (!error)
error = cp_new_stat(&stat, statbuf);
int error;

out:
return error;
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
return cp_new_stat(&stat, statbuf);
}
#endif

Expand Down Expand Up @@ -404,21 +413,12 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, char __user *, filename,
struct stat64 __user *, statbuf, int, flag)
{
struct kstat stat;
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);

if (!error)
error = cp_new_stat64(&stat, statbuf);
int error;

out:
return error;
error = vfs_fstatat(dfd, filename, &stat, flag);
if (error)
return error;
return cp_new_stat64(&stat, statbuf);
}
#endif /* __ARCH_WANT_STAT64 */

Expand Down
1 change: 1 addition & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_lstat_fd(int dfd, char __user *, 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,
unsigned long arg);
Expand Down

0 comments on commit 0112fc2

Please sign in to comment.