From 5421058c84eb456de8a5400142983ee3358a759f Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Sat, 29 Oct 2022 16:29:01 +0200 Subject: [PATCH] squash! stat --- include/linux/m2/kernel-stat.h | 47 ++++++++++++++++++ include/linux/x86/kernel-stat.h | 74 +++++++++++++++++++++++++++++ include/linux/x86_64/kernel-stat.h | 51 ++++++++++++++++++++ include/sys/stat.h | 76 +----------------------------- kaem.run | 1 + lib/linux/fstat.c | 2 +- lib/linux/lstat.c | 2 +- lib/linux/stat.c | 2 +- 8 files changed, 178 insertions(+), 77 deletions(-) create mode 100644 include/linux/m2/kernel-stat.h create mode 100644 include/linux/x86/kernel-stat.h create mode 100644 include/linux/x86_64/kernel-stat.h diff --git a/include/linux/m2/kernel-stat.h b/include/linux/m2/kernel-stat.h new file mode 100644 index 00000000..a5993778 --- /dev/null +++ b/include/linux/m2/kernel-stat.h @@ -0,0 +1,47 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ +#ifndef __LINUX_M2_KERNEL_STAT_H +#define __LINUX_M2_KERNEL_STAT_H + +// https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/stat.h + +// *INDENT-OFF* +struct stat +{ + unsigned st_dev; + unsigned st_ino; + char st_mode[2]; + char st_nlink[2]; + char st_uid[2]; + char st_gid[2]; + unsigned st_rdev; + unsigned st_size; + unsigned st_blksize; + unsigned st_blocks; + unsigned st_atime; + unsigned st_atime_usec; + unsigned st_mtime; + unsigned st_mtime_usec; + unsigned st_ctime; + unsigned st_ctime_usec; + unsigned __pad0; + unsigned __pad1; +}; +#endif // __LINUX_M2_KERNEL_STAT_H diff --git a/include/linux/x86/kernel-stat.h b/include/linux/x86/kernel-stat.h new file mode 100644 index 00000000..0231f250 --- /dev/null +++ b/include/linux/x86/kernel-stat.h @@ -0,0 +1,74 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ +#ifndef __MES_LINUX_X86_KERNEL_STAT_H +#define __MES_LINUX_X86_KERNEL_STAT_H 1 + +// https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/stat.h + +// *INDENT-OFF* +#if !SYS_stat64 || !HAVE_LONG_LONG +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned long st_rdev; + unsigned long st_size; + unsigned long st_blksize; + unsigned long st_blocks; + unsigned long st_atime; + unsigned long st_atime_usec; + unsigned long st_mtime; + unsigned long st_mtime_usec; + unsigned long st_ctime; + unsigned long st_ctime_usec; + unsigned long __pad0; + unsigned long __pad1; +}; +#else // ! (!SYS_stat64 || !HAVE_LONG_LONG) +// struct stat64 +struct stat +{ + unsigned long long st_dev; + unsigned char __pad0[4]; + unsigned long __st_ino; + unsigned int st_mode; + unsigned int st_nlink; + unsigned long st_uid; + unsigned long st_gid; + unsigned long long st_rdev; + unsigned char __pad3[4]; + long long st_size; + unsigned long st_blksize; + unsigned long long st_blocks; + unsigned long st_atime; + unsigned long st_atime_nsec; + unsigned long st_mtime; + unsigned int st_mtime_nsec; + unsigned long st_ctime; + unsigned long st_ctime_nsec; + unsigned long long st_ino; +}; +#endif // ! (!SYS_stat64 || !HAVE_LONG_LONG) + +#endif // __MES_LINUX_X86_KERNEL_STAT_H diff --git a/include/linux/x86_64/kernel-stat.h b/include/linux/x86_64/kernel-stat.h new file mode 100644 index 00000000..fdb15946 --- /dev/null +++ b/include/linux/x86_64/kernel-stat.h @@ -0,0 +1,51 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2017,2022 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ +#ifndef __MES_LINUX_X86_64_KERNEL_STAT_H +#define __MES_LINUX_X86_64_KERNEL_STAT_H 1 + +// https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/stat.h + +// *INDENT-OFF* +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned long st_nlink; + unsigned int st_mode; + unsigned int st_uid; + unsigned int st_gid; + unsigned int __pad0; + unsigned long st_rdev; + unsigned long st_size; + unsigned long st_atime; + unsigned long st_atime_nsec; + unsigned long st_mtime; + unsigned long st_mtime_nsec; + unsigned long st_ctime; + unsigned long st_ctime_nsec; + unsigned long st_blksize; + long st_blocks; + unsigned long __pad1; + unsigned long __pad2; + unsigned long __pad3; + unsigned long __pad4; +}; + +#endif // __MES_LINUX_X86_64_KERNEL_STAT_H diff --git a/include/sys/stat.h b/include/sys/stat.h index 52bacbd6..59ba513d 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -19,7 +19,7 @@ * along with GNU Mes. If not, see . */ #ifndef __MES_SYS_STAT_H -#define __MES_SYS_STAT_H 1lei +#define __MES_SYS_STAT_H 1 #if SYSTEM_LIBC #undef __MES_SYS_STAT_H @@ -30,85 +30,13 @@ #include #include #include +#include #ifndef __MES_MODE_T #define __MES_MODE_T typedef int mode_t; #endif -// *INDENT-OFF* -#if __M2__ -struct stat -{ - unsigned st_dev; - unsigned st_ino; - unsigned st_mode; - unsigned st_nlink; - unsigned st_uid; - unsigned st_gid; - unsigned st_rdev; - long st_size; /* Linux: unsigned long; glibc: off_t (i.e. signed) */ - unsigned st_blksize; - unsigned st_blocks; - time_t st_atime; /* Linux: unsigned long; glibc: time_t */ - unsigned st_atime_usec; - time_t st_mtime; /* Linux: unsigned long; glibc: time_t */ - unsigned st_mtime_usec; - time_t st_ctime; /* Linux: unsigned long; glibc: time_t */ - unsigned st_ctime_usec; - unsigned __foo0; - unsigned __foo1; -}; -// FIXME: M2-Planet 1.10.0 crashes on this... -// #elif (__i386__ || __arm__) && !SYS_stat64 -#define __i386__or__arm__ (__i386__or__arm__) -#elif __i386__or__arm__ && !SYS_stat64 -struct stat -{ - unsigned long st_dev; - unsigned long st_ino; - unsigned short st_mode; - unsigned short st_nlink; - unsigned short st_uid; - unsigned short st_gid; - unsigned long st_rdev; - long st_size; /* Linux: unsigned long; glibc: off_t (i.e. signed) */ - unsigned long st_blksize; - unsigned long st_blocks; - time_t st_atime; /* Linux: unsigned long; glibc: time_t */ - unsigned long st_atime_usec; - time_t st_mtime; /* Linux: unsigned long; glibc: time_t */ - unsigned long st_mtime_usec; - time_t st_ctime; /* Linux: unsigned long; glibc: time_t */ - unsigned long st_ctime_usec; - unsigned long __foo0; - unsigned long __foo1; -}; -#else -struct stat -{ - unsigned long st_dev; - unsigned long st_ino; - unsigned int st_mode; - unsigned int st_nlink; - unsigned int st_uid; - unsigned int st_gid; - unsigned long st_rdev; - long st_size; - unsigned long st_blksize; - unsigned long st_blocks; - time_t st_atime; - unsigned long st_atime_usec; - time_t st_mtime; - unsigned long st_mtime_usec; - time_t st_ctime; - unsigned long st_ctime_usec; - unsigned long __foo0; - unsigned long __foo1; -}; -#endif -// *INDENT-ON* - int chmod (char const *file_name, mode_t mode); int fstat (int filedes, struct stat *buf); int mkdir (char const *file_name, mode_t mode); diff --git a/kaem.run b/kaem.run index e607b5c0..64a270ca 100644 --- a/kaem.run +++ b/kaem.run @@ -88,6 +88,7 @@ M2-Planet \ -f lib/mes/fdungetc.c \ -f lib/posix/setenv.c \ -f lib/linux/access.c \ + -f include/linux/m2/kernel-stat.h \ -f include/sys/stat.h \ -f lib/linux/chmod.c \ -f lib/linux/ioctl3.c \ diff --git a/lib/linux/fstat.c b/lib/linux/fstat.c index 7e5be794..b6a4ff3b 100644 --- a/lib/linux/fstat.c +++ b/lib/linux/fstat.c @@ -22,7 +22,7 @@ #include #include -#if (__i386__ || __arm__) && SYS_fstat64 +#if (__i386__ || __arm__) && SYS_fstat64 && HAVE_LONG_LONG #undef SYS_fstat #define SYS_fstat SYS_fstat64 #endif diff --git a/lib/linux/lstat.c b/lib/linux/lstat.c index 1fa19d02..f929cee8 100644 --- a/lib/linux/lstat.c +++ b/lib/linux/lstat.c @@ -22,7 +22,7 @@ #include #include -#if (__i386__ || __arm__) && SYS_lstat64 +#if (__i386__ || __arm__) && SYS_lstat64 && HAVE_LONG_LONG #undef SYS_lstat #define SYS_lstat SYS_lstat64 #endif diff --git a/lib/linux/stat.c b/lib/linux/stat.c index 431eff5f..3463024f 100644 --- a/lib/linux/stat.c +++ b/lib/linux/stat.c @@ -22,7 +22,7 @@ #include #include -#if (__i386__ || __arm__) && SYS_stat64 +#if (__i386__ || __arm__) && SYS_stat64 && HAVE_LONG_LONG #undef SYS_stat #define SYS_stat SYS_stat64 #endif