From: Oleg Drokin <green@linuxhacker.ru>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Separate out common fstatat code
Date: Wed, 8 Apr 2009 09:54:11 +0400 [thread overview]
Message-ID: <20090408055411.GA1615245@fiona.linuxhacker.ru> (raw)
[-- Attachment #1: Type: text/plain, Size: 601 bytes --]
Hello!
It seems we have way too many copy&pasted fstatat code elsewhere which
might not have been a problem until now, but with all the changes
with "stat light" now and who knows what other additions in there in
the future, it really helps if we have only one copy of the code.
Hence this patch adds fstatat_common() that fills struct kstat with
proper values and does all the AT flags parsing that's needed and
then calls all the proper underlying functions, what's left to the
caller now is to only copy filled out kstat buffer to the final
destination.
Bye,
Oleg
[-- Attachment #2: fstatat_common_code.diff --]
[-- Type: text/plain, Size: 6675 bytes --]
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
arch/arm/kernel/sys_oabi-compat.c | 14 +++-----------
arch/s390/kernel/compat_linux.c | 12 ++----------
arch/sparc/kernel/sys_sparc32.c | 12 ++----------
arch/x86/ia32/sys_ia32.c | 12 ++----------
fs/compat.c | 12 ++----------
fs/stat.c | 34 +++++++++++++++++-----------------
include/linux/fs.h | 1 +
7 files changed, 29 insertions(+), 68 deletions(-)
Index: linux-2.6.29/arch/arm/kernel/sys_oabi-compat.c
===================================================================
--- linux-2.6.29.orig/arch/arm/kernel/sys_oabi-compat.c 2009-04-08 01:31:41.000000000 -0400
+++ linux-2.6.29/arch/arm/kernel/sys_oabi-compat.c 2009-04-08 01:41:59.000000000 -0400
@@ -176,20 +176,12 @@
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;
+ error = fstatat_common(dfd, filename, &stat, flag);
if (!error)
- error = cp_oldabi_stat64(&stat, statbuf);
+ error = cp_oldabi_stat64(&stat, statbuf);
-out:
return error;
}
Index: linux-2.6.29/arch/s390/kernel/compat_linux.c
===================================================================
--- linux-2.6.29.orig/arch/s390/kernel/compat_linux.c 2009-04-08 01:31:41.000000000 -0400
+++ linux-2.6.29/arch/s390/kernel/compat_linux.c 2009-04-08 01:40:31.000000000 -0400
@@ -702,19 +702,11 @@
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;
+ error = fstatat_common(dfd, filename, &stat, flag);
if (!error)
error = cp_stat64(statbuf, &stat);
-out:
return error;
}
Index: linux-2.6.29/arch/sparc/kernel/sys_sparc32.c
===================================================================
--- linux-2.6.29.orig/arch/sparc/kernel/sys_sparc32.c 2009-04-08 01:31:41.000000000 -0400
+++ linux-2.6.29/arch/sparc/kernel/sys_sparc32.c 2009-04-08 01:42:32.000000000 -0400
@@ -206,20 +206,12 @@
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);
+ int error;
+ error = fstatat_common(dfd, filename, &stat, flag);
if (!error)
error = cp_compat_stat64(&stat, statbuf);
-out:
return error;
}
Index: linux-2.6.29/arch/x86/ia32/sys_ia32.c
===================================================================
--- linux-2.6.29.orig/arch/x86/ia32/sys_ia32.c 2009-04-08 01:31:41.000000000 -0400
+++ linux-2.6.29/arch/x86/ia32/sys_ia32.c 2009-04-08 01:43:02.000000000 -0400
@@ -129,20 +129,12 @@
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);
+ int error;
+ error = fstatat_common(dfd, filename, &stat, flag);
if (!error)
error = cp_stat64(statbuf, &stat);
-out:
return error;
}
Index: linux-2.6.29/fs/compat.c
===================================================================
--- linux-2.6.29.orig/fs/compat.c 2009-04-08 01:31:41.000000000 -0400
+++ linux-2.6.29/fs/compat.c 2009-04-08 01:43:36.000000000 -0400
@@ -203,20 +203,12 @@
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);
+ int error;
+ error = fstatat_common(dfd, filename, &stat, flag);
if (!error)
error = cp_compat_stat(&stat, statbuf);
-out:
return error;
}
#endif
Index: linux-2.6.29/fs/stat.c
===================================================================
--- linux-2.6.29.orig/fs/stat.c 2009-04-08 01:31:41.000000000 -0400
+++ linux-2.6.29/fs/stat.c 2009-04-08 01:45:21.000000000 -0400
@@ -259,25 +259,33 @@
return error;
}
-#if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
-SYSCALL_DEFINE4(newfstatat, int, dfd, char __user *, filename,
- struct stat __user *, statbuf, int, flag)
+int fstatat_common(int dfd, char __user *filename, struct kstat *stat, 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);
+ error = vfs_lstat_fd(dfd, filename, stat);
else
- error = vfs_stat_fd(dfd, filename, &stat);
+ error = vfs_stat_fd(dfd, filename, stat);
+out:
+ return error;
+}
+EXPORT_SYMBOL(fstatat_common);
+
+#if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
+SYSCALL_DEFINE4(newfstatat, int, dfd, char __user *, filename,
+ struct stat __user *, statbuf, int, flag)
+{
+ struct kstat stat;
+ int error;
+ error = fstatat_common(dfd, filename, &stat, flag);
if (!error)
error = cp_new_stat(&stat, statbuf);
-out:
return error;
}
#endif
@@ -404,20 +412,12 @@
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);
+ int error;
+ error = fstatat_common(dfd, filename, &stat, flag);
if (!error)
error = cp_new_stat64(&stat, statbuf);
-out:
return error;
}
#endif /* __ARCH_WANT_STAT64 */
Index: linux-2.6.29/include/linux/fs.h
===================================================================
--- linux-2.6.29.orig/include/linux/fs.h 2009-04-08 01:31:41.000000000 -0400
+++ linux-2.6.29/include/linux/fs.h 2009-04-08 01:38:36.000000000 -0400
@@ -2075,6 +2075,7 @@
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 fstatat_common(int , char __user *, struct kstat *, int);
extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
unsigned long arg);
next reply other threads:[~2009-04-08 5:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-08 5:54 Oleg Drokin [this message]
2009-04-08 13:27 ` [PATCH] Separate out common fstatat code Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090408055411.GA1615245@fiona.linuxhacker.ru \
--to=green@linuxhacker.ru \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).