summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2012-02-03 20:06:55 -0800
committerKhem Raj <raj.khem@gmail.com>2012-02-05 12:11:26 -0800
commitae0e6225db6dacb4d4de81245fba8671526dfe90 (patch)
tree335d1f4ba329d7de195a3f87daa8e71e9d3a3e84 /libc/sysdeps/linux/common
parent812ae602fe96bb40d1743d410eb1eadb6aa722f5 (diff)
lstat/stat/fstat: Use 64bit version of syscall if available
This is needed for stat'ing loop devices > 255 since otherwise kernel returns EOVERFLOW becasue it needs st_rdev/st_dev to be larger than 16bits but in kernel it uses __old_kernel_stat for stat syscall which has st_rdev/st_dev as unsigned short Add a testcase Signed-off-by: Khem Raj <raj.khem@gmail.com>
Diffstat (limited to 'libc/sysdeps/linux/common')
-rw-r--r--libc/sysdeps/linux/common/fstat.c18
-rw-r--r--libc/sysdeps/linux/common/lstat.c19
-rw-r--r--libc/sysdeps/linux/common/stat.c18
3 files changed, 42 insertions, 13 deletions
diff --git a/libc/sysdeps/linux/common/fstat.c b/libc/sysdeps/linux/common/fstat.c
index acc639bce..4726a6879 100644
--- a/libc/sysdeps/linux/common/fstat.c
+++ b/libc/sysdeps/linux/common/fstat.c
@@ -12,18 +12,28 @@
#include <sys/stat.h>
#include "xstatconv.h"
-#define __NR___syscall_fstat __NR_fstat
-static __inline__ _syscall2(int, __syscall_fstat, int, fd, struct kernel_stat *, buf)
-
int fstat(int fd, struct stat *buf)
{
int result;
+#ifdef __NR_fstat64
+ /* normal stat call has limited values for various stat elements
+ * e.g. uid device major/minor etc.
+ * so we use 64 variant if available
+ * in order to get newer versions of stat elements
+ */
+ struct kernel_stat64 kbuf;
+ result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
+ if (result == 0) {
+ __xstat32_conv(&kbuf, buf);
+ }
+#else
struct kernel_stat kbuf;
- result = __syscall_fstat(fd, &kbuf);
+ result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
if (result == 0) {
__xstat_conv(&kbuf, buf);
}
+#endif
return result;
}
libc_hidden_def(fstat)
diff --git a/libc/sysdeps/linux/common/lstat.c b/libc/sysdeps/linux/common/lstat.c
index aa774473c..db72d1f60 100644
--- a/libc/sysdeps/linux/common/lstat.c
+++ b/libc/sysdeps/linux/common/lstat.c
@@ -12,19 +12,28 @@
#include <sys/stat.h>
#include "xstatconv.h"
-#define __NR___syscall_lstat __NR_lstat
-static __inline__ _syscall2(int, __syscall_lstat,
- const char *, file_name, struct kernel_stat *, buf)
-
int lstat(const char *file_name, struct stat *buf)
{
int result;
+#ifdef __NR_lstat64
+ /* normal stat call has limited values for various stat elements
+ * e.g. uid device major/minor etc.
+ * so we use 64 variant if available
+ * in order to get newer versions of stat elements
+ */
+ struct kernel_stat64 kbuf;
+ result = INLINE_SYSCALL(lstat64, 2, file_name, &kbuf);
+ if (result == 0) {
+ __xstat32_conv(&kbuf, buf);
+ }
+#else
struct kernel_stat kbuf;
- result = __syscall_lstat(file_name, &kbuf);
+ result = INLINE_SYSCALL(lstat, 2, file_name, &kbuf);
if (result == 0) {
__xstat_conv(&kbuf, buf);
}
+#endif
return result;
}
libc_hidden_def(lstat)
diff --git a/libc/sysdeps/linux/common/stat.c b/libc/sysdeps/linux/common/stat.c
index a6ab291f2..829f35a93 100644
--- a/libc/sysdeps/linux/common/stat.c
+++ b/libc/sysdeps/linux/common/stat.c
@@ -12,20 +12,30 @@
#include <sys/stat.h>
#include "xstatconv.h"
-#define __NR___syscall_stat __NR_stat
#undef stat
-static __inline__ _syscall2(int, __syscall_stat,
- const char *, file_name, struct kernel_stat *, buf)
int stat(const char *file_name, struct stat *buf)
{
int result;
+#ifdef __NR_stat64
+ /* normal stat call has limited values for various stat elements
+ * e.g. uid device major/minor etc.
+ * so we use 64 variant if available
+ * in order to get newer versions of stat elements
+ */
+ struct kernel_stat64 kbuf;
+ result = INLINE_SYSCALL(stat64, 2, file_name, &kbuf);
+ if (result == 0) {
+ __xstat32_conv(&kbuf, buf);
+ }
+#else
struct kernel_stat kbuf;
- result = __syscall_stat(file_name, &kbuf);
+ result = INLINE_SYSCALL(stat, 2, file_name, &kbuf);
if (result == 0) {
__xstat_conv(&kbuf, buf);
}
+#endif
return result;
}
libc_hidden_def(stat)