summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux/common')
-rw-r--r--libc/sysdeps/linux/common/bits/kernel_stat.h36
-rw-r--r--libc/sysdeps/linux/common/bits/stat.h72
-rw-r--r--libc/sysdeps/linux/common/syscalls.c114
-rw-r--r--libc/sysdeps/linux/common/xstatconv.c103
4 files changed, 275 insertions, 50 deletions
diff --git a/libc/sysdeps/linux/common/bits/kernel_stat.h b/libc/sysdeps/linux/common/bits/kernel_stat.h
index b338e3d5c..04c984757 100644
--- a/libc/sysdeps/linux/common/bits/kernel_stat.h
+++ b/libc/sysdeps/linux/common/bits/kernel_stat.h
@@ -2,12 +2,11 @@
#define _BITS_STAT_STRUCT_H
/* This file provides whatever this particular arch's kernel thinks
- * struct stat should look like... It turns out each arch has a
+ * struct kernel_stat should look like... It turns out each arch has a
* different opinion on the subject... */
-#warning please verify struct stat for your architecture matches struct stat for x86...
+#warning "Please verify struct kernel_stat for your architecture actually matches struct kernel_stat for x86 If it doesn't, then you will need to add a proper kernel_stat.h for your architecture..."
-#ifndef __USE_FILE_OFFSET64
-struct stat {
+struct kernel_stat {
unsigned short st_dev;
unsigned short __pad1;
unsigned long st_ino;
@@ -29,34 +28,8 @@ struct stat {
unsigned long __unused4;
unsigned long __unused5;
};
-#else
-struct stat {
- unsigned short st_dev;
- unsigned char __pad0[10];
-#define STAT64_HAS_BROKEN_ST_INO 1
- unsigned long __st_ino;
- unsigned int st_mode;
- unsigned int st_nlink;
- unsigned long st_uid;
- unsigned long st_gid;
- unsigned short st_rdev;
- unsigned char __pad3[10];
- long long st_size;
- unsigned long st_blksize;
- unsigned long st_blocks; /* Number 512-byte blocks allocated. */
- unsigned long __pad4; /* future possible st_blocks high bits */
- unsigned long st_atime;
- unsigned long __pad5;
- unsigned long st_mtime;
- unsigned long __pad6;
- unsigned long st_ctime;
- unsigned long __pad7; /* will be high 32 bits of ctime someday */
- unsigned long long st_ino;
-};
-#endif
-#ifdef __USE_LARGEFILE64
-struct stat64 {
+struct kernel_stat64 {
unsigned short st_dev;
unsigned char __pad0[10];
#define STAT64_HAS_BROKEN_ST_INO 1
@@ -79,7 +52,6 @@ struct stat64 {
unsigned long __pad7; /* will be high 32 bits of ctime someday */
unsigned long long st_ino;
};
-#endif
#endif /* _BITS_STAT_STRUCT_H */
diff --git a/libc/sysdeps/linux/common/bits/stat.h b/libc/sysdeps/linux/common/bits/stat.h
index 942accda1..3ecec4a47 100644
--- a/libc/sysdeps/linux/common/bits/stat.h
+++ b/libc/sysdeps/linux/common/bits/stat.h
@@ -35,10 +35,74 @@
#define _MKNOD_VER_SVR4 2
#define _MKNOD_VER _MKNOD_VER_LINUX /* The bits defined below. */
-/* Pull in whatever this particular arch's kernel thinks that struct stat
- * should look like. It turns out that each arch has a different opinion
- * on the subject, and different kernel revs use different names... */
-#include <bits/kernel_stat.h>
+struct stat
+{
+ __dev_t st_dev; /* Device. */
+ unsigned short int __pad1;
+#ifndef __USE_FILE_OFFSET64
+ __ino_t st_ino; /* File serial number. */
+#else
+ __ino_t __st_ino; /* 32bit file serial number. */
+#endif
+ __mode_t st_mode; /* File mode. */
+ __nlink_t st_nlink; /* Link count. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __dev_t st_rdev; /* Device number, if device. */
+ unsigned short int __pad2;
+#ifndef __USE_FILE_OFFSET64
+ __off_t st_size; /* Size of file, in bytes. */
+#else
+ __off64_t st_size; /* Size of file, in bytes. */
+#endif
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+#ifndef __USE_FILE_OFFSET64
+ __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
+#else
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+#endif
+ __time_t st_atime; /* Time of last access. */
+ unsigned long int __unused1;
+ __time_t st_mtime; /* Time of last modification. */
+ unsigned long int __unused2;
+ __time_t st_ctime; /* Time of last status change. */
+ unsigned long int __unused3;
+#ifndef __USE_FILE_OFFSET64
+ unsigned long int __unused4;
+ unsigned long int __unused5;
+#else
+ __ino64_t st_ino; /* File serial number. */
+#endif
+};
+
+#ifdef __USE_LARGEFILE64
+struct stat64
+{
+ __dev_t st_dev; /* Device. */
+ unsigned int __pad1;
+
+ __ino_t __st_ino; /* 32bit file serial number. */
+ __mode_t st_mode; /* File mode. */
+ __nlink_t st_nlink; /* Link count. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __dev_t st_rdev; /* Device number, if device. */
+ unsigned int __pad2;
+ __off64_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+
+ __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
+ __time_t st_atime; /* Time of last access. */
+ unsigned long int __unused1;
+ __time_t st_mtime; /* Time of last modification. */
+ unsigned long int __unused2;
+ __time_t st_ctime; /* Time of last status change. */
+ unsigned long int __unused3;
+ __ino64_t st_ino; /* File serial number. */
+};
+#endif
+
/* Tell code we have these members. */
#define _STATBUF_ST_BLKSIZE
diff --git a/libc/sysdeps/linux/common/syscalls.c b/libc/sysdeps/linux/common/syscalls.c
index 6090d37db..867635856 100644
--- a/libc/sysdeps/linux/common/syscalls.c
+++ b/libc/sysdeps/linux/common/syscalls.c
@@ -156,9 +156,17 @@ time_t time (time_t *t)
#endif
//#define __NR_mknod 14
-#ifdef L_mknod
+#ifdef L___syscall_mknod
+#define __NR___syscall_mknod __NR_mknod
#include <sys/stat.h>
-_syscall3(int, mknod, const char *, path, mode_t, mode, dev_t, dev);
+_syscall3(int, __syscall_mknod, const char *, path, __kernel_mode_t, mode, __kernel_dev_t, dev);
+int mknod(const char *path, mode_t mode, dev_t dev)
+{
+ __kernel_dev_t k_dev;
+ /* We must convert the dev_t value to a __kernel_dev_t */
+ k_dev = ((major(dev) & 0xff) << 8) | (minor(dev) & 0xff);
+ return __syscall_mknod(path, mode, k_dev);
+}
#endif
//#define __NR_chmod 15
@@ -958,30 +966,69 @@ _syscall2(int, getitimer, __itimer_which_t, which, struct itimerval *, value);
#endif
//#define __NR_stat 106
-#ifdef L_stat
+#ifdef L___syscall_stat
+#define __NR___syscall_stat __NR_stat
#include <unistd.h>
#include <sys/stat.h>
-_syscall2(int, stat, const char *, file_name, struct stat *, buf);
+#include <bits/kernel_stat.h>
+#include "xstatconv.c"
+_syscall2(int, __syscall_stat, const char *, file_name, struct kernel_stat *, buf);
+int stat(const char * file_name, struct stat * buf)
+{
+ int result;
+ struct kernel_stat kbuf;
+ result = __syscall_stat(file_name, &kbuf);
+ if (result == 0) {
+ __xstat_conv(&kbuf, buf);
+ }
+ return result;
+}
#if ! defined __NR_stat64 && defined __UCLIBC_HAS_LFS__
weak_alias(stat, stat64);
#endif
#endif
//#define __NR_lstat 107
-#ifdef L_lstat
+#ifdef L___syscall_lstat
+#define __NR___syscall_lstat __NR_lstat
#include <unistd.h>
#include <sys/stat.h>
-_syscall2(int, lstat, const char *, file_name, struct stat *, buf);
+#include <bits/kernel_stat.h>
+#include "xstatconv.c"
+_syscall2(int, __syscall_lstat, const char *, file_name, struct kernel_stat *, buf);
+int lstat(const char * file_name, struct stat * buf)
+{
+ int result;
+ struct kernel_stat kbuf;
+ result = __syscall_lstat(file_name, &kbuf);
+ if (result == 0) {
+ __xstat_conv(&kbuf, buf);
+ }
+ return result;
+}
#if ! defined __NR_lstat64 && defined __UCLIBC_HAS_LFS__
weak_alias(lstat, lstat64);
#endif
#endif
//#define __NR_fstat 108
-#ifdef L_fstat
+#ifdef L___syscall_fstat
+#define __NR___syscall_fstat __NR_fstat
#include <unistd.h>
#include <sys/stat.h>
-_syscall2(int, fstat, int, filedes, struct stat *, buf);
+#include <bits/kernel_stat.h>
+#include "xstatconv.c"
+_syscall2(int, __syscall_fstat, int, fd, struct kernel_stat *, buf);
+int fstat(int fd, struct stat * buf)
+{
+ int result;
+ struct kernel_stat kbuf;
+ result = __syscall_fstat(fd, &kbuf);
+ if (result == 0) {
+ __xstat_conv(&kbuf, buf);
+ }
+ return result;
+}
#if ! defined __NR_fstat64 && defined __UCLIBC_HAS_LFS__
weak_alias(fstat, fstat64);
#endif
@@ -1623,29 +1670,68 @@ int getrlimit (__rlimit_resource_t resource, struct rlimit *rlimits)
//#define __NR_stat64 195
-#ifdef L_stat64
+#ifdef L___syscall_stat64
#if defined __NR_stat64 && defined __UCLIBC_HAS_LFS__
+#define __NR___syscall_stat64 __NR_stat64
#include <unistd.h>
#include <sys/stat.h>
-_syscall2(int, stat64, const char *, file_name, struct stat64 *, buf);
+#include <bits/kernel_stat.h>
+#include "xstatconv.c"
+_syscall2(int, __syscall_stat64, const char *, file_name, struct kernel_stat64 *, buf);
+int stat64(const char * file_name, struct stat64 * buf)
+{
+ int result;
+ struct kernel_stat64 kbuf;
+ result = __syscall_stat64(file_name, &kbuf);
+ if (result == 0) {
+ __xstat64_conv(&kbuf, buf);
+ }
+ return result;
+}
#endif /* __UCLIBC_HAS_LFS__ */
#endif
//#define __NR_lstat64 196
-#ifdef L_lstat64
+#ifdef L___syscall_lstat64
#if defined __NR_lstat64 && defined __UCLIBC_HAS_LFS__
+#define __NR___syscall_lstat64 __NR_lstat64
#include <unistd.h>
#include <sys/stat.h>
-_syscall2(int, lstat64, const char *, file_name, struct stat64 *, buf);
+#include <bits/kernel_stat.h>
+#include "xstatconv.c"
+_syscall2(int, __syscall_lstat64, const char *, file_name, struct kernel_stat64 *, buf);
+int lstat64(const char * file_name, struct stat64 * buf)
+{
+ int result;
+ struct kernel_stat64 kbuf;
+ result = __syscall_lstat64(file_name, &kbuf);
+ if (result == 0) {
+ __xstat64_conv(&kbuf, buf);
+ }
+ return result;
+}
#endif /* __UCLIBC_HAS_LFS__ */
#endif
//#define __NR_fstat64 197
-#ifdef L_fstat64
+#ifdef L___syscall_fstat64
#if defined __NR_fstat64 && defined __UCLIBC_HAS_LFS__
+#define __NR___syscall_fstat64 __NR_fstat64
#include <unistd.h>
#include <sys/stat.h>
-_syscall2(int, fstat64, int, filedes, struct stat64 *, buf);
+#include <bits/kernel_stat.h>
+#include "xstatconv.c"
+_syscall2(int, __syscall_fstat64, int, filedes, struct kernel_stat64 *, buf);
+int fstat64(int fd, struct stat64 * buf)
+{
+ int result;
+ struct kernel_stat64 kbuf;
+ result = __syscall_fstat64(fd, &kbuf);
+ if (result == 0) {
+ __xstat64_conv(&kbuf, buf);
+ }
+ return result;
+}
#endif /* __UCLIBC_HAS_LFS__ */
#endif
diff --git a/libc/sysdeps/linux/common/xstatconv.c b/libc/sysdeps/linux/common/xstatconv.c
new file mode 100644
index 000000000..c8d28d411
--- /dev/null
+++ b/libc/sysdeps/linux/common/xstatconv.c
@@ -0,0 +1,103 @@
+/* Convert between the kernel's `struct stat' format, and libc's.
+ Copyright (C) 1991,1995,1996,1997,2000,2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA.
+
+ Modified for uClibc by Erik Andersen <andersen@codepoet.org>
+ */
+
+static inline void __xstat_conv(struct kernel_stat *kbuf, struct stat *buf)
+{
+ /* Convert to current kernel version of `struct stat'. */
+ buf->st_dev = kbuf->st_dev;
+#ifdef _HAVE_STAT___PAD1
+ buf->__pad1 = 0;
+#endif
+ buf->st_ino = kbuf->st_ino;
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+#ifdef _HAVE_STAT___PAD2
+ buf->__pad2 = 0;
+#endif
+ buf->st_size = kbuf->st_size;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_blocks = kbuf->st_blocks;
+ buf->st_atime = kbuf->st_atime;
+#ifdef _HAVE_STAT___UNUSED1
+ buf->__unused1 = 0;
+#endif
+ buf->st_mtime = kbuf->st_mtime;
+#ifdef _HAVE_STAT___UNUSED2
+ buf->__unused2 = 0;
+#endif
+ buf->st_ctime = kbuf->st_ctime;
+#ifdef _HAVE_STAT___UNUSED3
+ buf->__unused3 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED4
+ buf->__unused4 = 0;
+#endif
+#ifdef _HAVE_STAT___UNUSED5
+ buf->__unused5 = 0;
+#endif
+}
+
+static inline void __xstat64_conv(struct kernel_stat64 *kbuf, struct stat64 *buf)
+{
+ /* Convert to current kernel version of `struct stat64'. */
+ buf->st_dev = kbuf->st_dev;
+#ifdef _HAVE_STAT64___PAD1
+ buf->__pad1 = 0;
+#endif
+ buf->st_ino = kbuf->st_ino;
+#ifdef _HAVE_STAT64___ST_INO
+ buf->__st_ino = kbuf->st_ino;
+#endif
+ buf->st_mode = kbuf->st_mode;
+ buf->st_nlink = kbuf->st_nlink;
+ buf->st_uid = kbuf->st_uid;
+ buf->st_gid = kbuf->st_gid;
+ buf->st_rdev = kbuf->st_rdev;
+#ifdef _HAVE_STAT64___PAD2
+ buf->__pad2 = 0;
+#endif
+ buf->st_size = kbuf->st_size;
+ buf->st_blksize = kbuf->st_blksize;
+ buf->st_blocks = kbuf->st_blocks;
+ buf->st_atime = kbuf->st_atime;
+#ifdef _HAVE_STAT64___UNUSED1
+ buf->__unused1 = 0;
+#endif
+ buf->st_mtime = kbuf->st_mtime;
+#ifdef _HAVE_STAT64___UNUSED2
+ buf->__unused2 = 0;
+#endif
+ buf->st_ctime = kbuf->st_ctime;
+#ifdef _HAVE_STAT64___UNUSED3
+ buf->__unused3 = 0;
+#endif
+#ifdef _HAVE_STAT64___UNUSED4
+ buf->__unused4 = 0;
+#endif
+#ifdef _HAVE_STAT64___UNUSED5
+ buf->__unused5 = 0;
+#endif
+}
+