* [PATCH v4 2/2] Define __STATFS_MATCHES_STATFS64
2019-10-16 23:48 [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Alistair Francis
@ 2019-10-16 23:48 ` Alistair Francis
2019-10-18 15:13 ` Joseph Myers
2019-10-18 15:08 ` [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Joseph Myers
1 sibling, 1 reply; 6+ messages in thread
From: Alistair Francis @ 2019-10-16 23:48 UTC (permalink / raw)
To: libc-alpha; +Cc: alistair23, Alistair Francis
Add a new macro __STATFS_MATCHES_STATFS64 that specifies if fsblkcnt_t
matches fsblkcnt64_t and if fsfilcnt_t matches fsfilcnt64_t.
On a 32-bit platform with a 64-bit ino_t type (__STATFS_MATCHES_STATFS64
== 1) we want to update the statfs struct to remove the padding as it
isn't required. As we don't have the padding we also need to update the
overflow checker to not access the undefined members.
* bits/typesizes.h: Define __STATFS_MATCHES_STATFS64 to handle
64-bit __fsblkcnt_t and __fsfilcnt_t types on 32-bit hosts.
* sysdeps/unix/sysv/linux/generic/bits/statfs.h: Likewise.
* sysdeps/unix/sysv/linux/generic/bits/typesizes.h: Likewise.
* sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h: Likewise.
* sysdeps/unix/sysv/linux/s390/bits/typesizes.h: Likewise.
* sysdeps/unix/sysv/linux/sparc/bits/typesizes.h: Likewise.
* sysdeps/unix/sysv/linux/x86/bits/typesizes.h: Likewise.
---
bits/typesizes.h | 5 +++++
sysdeps/unix/sysv/linux/generic/bits/statfs.h | 2 +-
sysdeps/unix/sysv/linux/generic/bits/typesizes.h | 6 +++++-
sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h | 4 ++++
sysdeps/unix/sysv/linux/s390/bits/typesizes.h | 5 +++++
sysdeps/unix/sysv/linux/sparc/bits/typesizes.h | 5 +++++
sysdeps/unix/sysv/linux/x86/bits/typesizes.h | 5 +++++
7 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/bits/typesizes.h b/bits/typesizes.h
index 779945bf099..ae6eff5fc5f 100644
--- a/bits/typesizes.h
+++ b/bits/typesizes.h
@@ -72,8 +72,13 @@
/* And for rlim_t and rlim64_t. */
# define __RLIM_T_MATCHES_RLIM64_T 1
+
+/* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t. */
+# define __STATFS_MATCHES_STATFS64 1
#else
# define __RLIM_T_MATCHES_RLIM64_T 0
+
+# define __STATFS_MATCHES_STATFS64 0
#endif
/* Number of descriptors that can fit in an `fd_set'. */
diff --git a/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index c4069aba620..e622daf2240 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -34,7 +34,7 @@
#if defined __USE_FILE_OFFSET64
# define __field64(type, type64, name) type64 name
-#elif __WORDSIZE == 64
+#elif __WORDSIZE == 64 || __STATFS_MATCHES_STATFS64
# define __field64(type, type64, name) type name
#elif __BYTE_ORDER == __LITTLE_ENDIAN
# define __field64(type, type64, name) \
diff --git a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
index 05e3cfee454..0c8c2e0c12a 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/typesizes.h
@@ -73,10 +73,14 @@
/* And for __rlim_t and __rlim64_t. */
# define __RLIM_T_MATCHES_RLIM64_T 1
+
+/* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t. */
+# define __STATFS_MATCHES_STATFS64 1
#else
# define __RLIM_T_MATCHES_RLIM64_T 0
-#endif
+# define __STATFS_MATCHES_STATFS64 0
+#endif
/* Number of descriptors that can fit in an `fd_set'. */
#define __FD_SETSIZE 1024
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
index 66546b07ccd..f63dbfae899 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
@@ -51,6 +51,9 @@ static inline int stat_overflow (struct stat *buf)
/* Note that f_files and f_ffree may validly be a sign-extended -1. */
static inline int statfs_overflow (struct statfs *buf)
{
+#if __STATFS_MATCHES_STATFS64
+ return 0;
+#else
if (buf->__f_blocks_pad == 0 && buf->__f_bfree_pad == 0
&& buf->__f_bavail_pad == 0
&& (buf->__f_files_pad == 0
@@ -61,4 +64,5 @@ static inline int statfs_overflow (struct statfs *buf)
__set_errno (EOVERFLOW);
return -1;
+#endif
}
diff --git a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
index 94234f92427..38034e3ad40 100644
--- a/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/s390/bits/typesizes.h
@@ -78,8 +78,13 @@
/* And for __rlim_t and __rlim64_t. */
# define __RLIM_T_MATCHES_RLIM64_T 1
+
+/* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t. */
+# define __STATFS_MATCHES_STATFS64 1
#else
# define __RLIM_T_MATCHES_RLIM64_T 0
+
+# define __STATFS_MATCHES_STATFS64 0
#endif
/* Number of descriptors that can fit in an `fd_set'. */
diff --git a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
index 037f530d65b..c93f428017b 100644
--- a/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
@@ -72,8 +72,13 @@
/* And for __rlim_t and __rlim64_t. */
# define __RLIM_T_MATCHES_RLIM64_T 1
+
+/* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t. */
+# define __STATFS_MATCHES_STATFS64 1
#else
# define __RLIM_T_MATCHES_RLIM64_T 0
+
+# define __STATFS_MATCHES_STATFS64 0
#endif
/* Number of descriptors that can fit in an `fd_set'. */
diff --git a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
index 012651b3ab5..168990f9dda 100644
--- a/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
+++ b/sysdeps/unix/sysv/linux/x86/bits/typesizes.h
@@ -84,8 +84,13 @@
/* And for __rlim_t and __rlim64_t. */
# define __RLIM_T_MATCHES_RLIM64_T 1
+
+/* And for fsblkcnt_t, fsblkcnt64_t, fsfilcnt_t and fsfilcnt64_t. */
+# define __STATFS_MATCHES_STATFS64 1
#else
# define __RLIM_T_MATCHES_RLIM64_T 0
+
+# define __STATFS_MATCHES_STATFS64 0
#endif
/* Number of descriptors that can fit in an `fd_set'. */
--
2.23.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts
@ 2019-10-16 23:48 Alistair Francis
2019-10-16 23:48 ` [PATCH v4 2/2] Define __STATFS_MATCHES_STATFS64 Alistair Francis
2019-10-18 15:08 ` [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Joseph Myers
0 siblings, 2 replies; 6+ messages in thread
From: Alistair Francis @ 2019-10-16 23:48 UTC (permalink / raw)
To: libc-alpha; +Cc: alistair23, Alistair Francis
On a 32-bit platform with a 64-bit ino_t type (__INO_T_MATCHES_INO64_T
defined) we want to update the stat struct to remove the padding as it
isn't required. As we don't have the padding we also need to update the
overflow checker to not access the undefined members.
* sysdeps/unix/sysv/linux/generic/bits/stat.h: Handle 64-bit ino_t types
on 32-bit hosts.
* sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h: Likewise.
* sysdeps/unix/sysv/linux/generic/xstat.c: Ensure __blkcnt_t == __blkcnt64_t
if __INO_T_MATCHES_INO64_T is defined.
---
sysdeps/unix/sysv/linux/generic/bits/stat.h | 5 ++++-
sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h | 4 ++++
sysdeps/unix/sysv/linux/generic/xstat.c | 5 +++++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
index 1565f3f8248..34c455ed786 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
@@ -42,7 +42,10 @@
#if defined __USE_FILE_OFFSET64
# define __field64(type, type64, name) type64 name
-#elif __WORDSIZE == 64
+#elif __WORDSIZE == 64 || defined __INO_T_MATCHES_INO64_T
+# if defined __INO_T_MATCHES_INO64_T && !defined __OFF_T_MATCHES_OFF64_T
+# error "ino_t and off_t must both be the same type"
+# endif
# define __field64(type, type64, name) type name
#elif __BYTE_ORDER == __LITTLE_ENDIAN
# define __field64(type, type64, name) \
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
index 45efcd8fd34..66546b07ccd 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
@@ -36,12 +36,16 @@ static inline off_t lseek_overflow (loff_t res)
static inline int stat_overflow (struct stat *buf)
{
+#if defined __INO_T_MATCHES_INO64_T
+ return 0;
+#else
if (buf->__st_ino_pad == 0 && buf->__st_size_pad == 0
&& buf->__st_blocks_pad == 0)
return 0;
__set_errno (EOVERFLOW);
return -1;
+#endif
}
/* Note that f_files and f_ffree may validly be a sign-extended -1. */
diff --git a/sysdeps/unix/sysv/linux/generic/xstat.c b/sysdeps/unix/sysv/linux/generic/xstat.c
index 75ceb9bc74b..ece14fc5838 100644
--- a/sysdeps/unix/sysv/linux/generic/xstat.c
+++ b/sysdeps/unix/sysv/linux/generic/xstat.c
@@ -28,6 +28,11 @@
#include <sysdep.h>
#include <sys/syscall.h>
+#if __INO_T_MATCHES_INO64_T
+_Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t),
+ "__blkcnt_t and __blkcnt64_t must match");
+#endif
+
/* Get information about the file NAME in BUF. */
int
__xstat (int vers, const char *name, struct stat *buf)
--
2.23.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts
2019-10-16 23:48 [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Alistair Francis
2019-10-16 23:48 ` [PATCH v4 2/2] Define __STATFS_MATCHES_STATFS64 Alistair Francis
@ 2019-10-18 15:08 ` Joseph Myers
2019-10-18 21:25 ` Alistair Francis
1 sibling, 1 reply; 6+ messages in thread
From: Joseph Myers @ 2019-10-18 15:08 UTC (permalink / raw)
To: Alistair Francis; +Cc: libc-alpha, alistair23
On Wed, 16 Oct 2019, Alistair Francis wrote:
> diff --git a/sysdeps/unix/sysv/linux/generic/xstat.c b/sysdeps/unix/sysv/linux/generic/xstat.c
> index 75ceb9bc74b..ece14fc5838 100644
> --- a/sysdeps/unix/sysv/linux/generic/xstat.c
> +++ b/sysdeps/unix/sysv/linux/generic/xstat.c
> @@ -28,6 +28,11 @@
> #include <sysdep.h>
> #include <sys/syscall.h>
>
> +#if __INO_T_MATCHES_INO64_T
> +_Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t),
> + "__blkcnt_t and __blkcnt64_t must match");
> +#endif
This isn't a good place for this check because this file is overridden for
wordsize-32, meaning the check is missing in the wordsize-32 case. It
needs to go somewhere used whether or not the wordsize-32 subdirectory is
in use. (You could e.g. have a source file used only for this check, that
compiles to an object file with no code.)
I think this assertion should also have a comment explaining that it's
because the layout code in bits/stat.h, and the overflow handling in
wordsize-32/overflow.h, require either all or none of the three types
concerned to have padding.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 2/2] Define __STATFS_MATCHES_STATFS64
2019-10-16 23:48 ` [PATCH v4 2/2] Define __STATFS_MATCHES_STATFS64 Alistair Francis
@ 2019-10-18 15:13 ` Joseph Myers
2019-10-18 21:29 ` Alistair Francis
0 siblings, 1 reply; 6+ messages in thread
From: Joseph Myers @ 2019-10-18 15:13 UTC (permalink / raw)
To: Alistair Francis; +Cc: libc-alpha, alistair23
On Wed, 16 Oct 2019, Alistair Francis wrote:
> Add a new macro __STATFS_MATCHES_STATFS64 that specifies if fsblkcnt_t
> matches fsblkcnt64_t and if fsfilcnt_t matches fsfilcnt64_t.
>
> On a 32-bit platform with a 64-bit ino_t type (__STATFS_MATCHES_STATFS64
> == 1) we want to update the statfs struct to remove the padding as it
> isn't required. As we don't have the padding we also need to update the
> overflow checker to not access the undefined members.
>
> * bits/typesizes.h: Define __STATFS_MATCHES_STATFS64 to handle
> 64-bit __fsblkcnt_t and __fsfilcnt_t types on 32-bit hosts.
> * sysdeps/unix/sysv/linux/generic/bits/statfs.h: Likewise.
> * sysdeps/unix/sysv/linux/generic/bits/typesizes.h: Likewise.
> * sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h: Likewise.
> * sysdeps/unix/sysv/linux/s390/bits/typesizes.h: Likewise.
> * sysdeps/unix/sysv/linux/sparc/bits/typesizes.h: Likewise.
> * sysdeps/unix/sysv/linux/x86/bits/typesizes.h: Likewise.
Note that you no longer need to write ChangeLog entries.
I don't follow the logic for which bits/typesizes.h headers you're
updating. You're updating some for architectures not using linux/generic,
which I think is the right thing to do - make them provide the defined
API, whether or not they currently use any code that actually tests the
__STATFS_MATCHES_STATFS64 macro. But you're not updating
sysdeps/unix/sysv/linux/alpha/bits/typesizes.h or
sysdeps/mach/hurd/bits/typesizes.h; I'd expect those to be updated as well
for consistency.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts
2019-10-18 15:08 ` [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Joseph Myers
@ 2019-10-18 21:25 ` Alistair Francis
0 siblings, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2019-10-18 21:25 UTC (permalink / raw)
To: Joseph Myers; +Cc: Alistair Francis, GNU C Library, alistair23
On Fri, Oct 18, 2019 at 8:08 AM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Wed, 16 Oct 2019, Alistair Francis wrote:
>
> > diff --git a/sysdeps/unix/sysv/linux/generic/xstat.c b/sysdeps/unix/sysv/linux/generic/xstat.c
> > index 75ceb9bc74b..ece14fc5838 100644
> > --- a/sysdeps/unix/sysv/linux/generic/xstat.c
> > +++ b/sysdeps/unix/sysv/linux/generic/xstat.c
> > @@ -28,6 +28,11 @@
> > #include <sysdep.h>
> > #include <sys/syscall.h>
> >
> > +#if __INO_T_MATCHES_INO64_T
> > +_Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t),
> > + "__blkcnt_t and __blkcnt64_t must match");
> > +#endif
>
> This isn't a good place for this check because this file is overridden for
> wordsize-32, meaning the check is missing in the wordsize-32 case. It
> needs to go somewhere used whether or not the wordsize-32 subdirectory is
> in use. (You could e.g. have a source file used only for this check, that
> compiles to an object file with no code.)
Ok, I have added a file: sysdeps/unix/sysv/linux/generic/stat-check.c
>
> I think this assertion should also have a comment explaining that it's
> because the layout code in bits/stat.h, and the overflow handling in
> wordsize-32/overflow.h, require either all or none of the three types
> concerned to have padding.
Done!
Alistair
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v4 2/2] Define __STATFS_MATCHES_STATFS64
2019-10-18 15:13 ` Joseph Myers
@ 2019-10-18 21:29 ` Alistair Francis
0 siblings, 0 replies; 6+ messages in thread
From: Alistair Francis @ 2019-10-18 21:29 UTC (permalink / raw)
To: Joseph Myers; +Cc: Alistair Francis, GNU C Library, alistair23
On Fri, Oct 18, 2019 at 8:14 AM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Wed, 16 Oct 2019, Alistair Francis wrote:
>
> > Add a new macro __STATFS_MATCHES_STATFS64 that specifies if fsblkcnt_t
> > matches fsblkcnt64_t and if fsfilcnt_t matches fsfilcnt64_t.
> >
> > On a 32-bit platform with a 64-bit ino_t type (__STATFS_MATCHES_STATFS64
> > == 1) we want to update the statfs struct to remove the padding as it
> > isn't required. As we don't have the padding we also need to update the
> > overflow checker to not access the undefined members.
> >
> > * bits/typesizes.h: Define __STATFS_MATCHES_STATFS64 to handle
> > 64-bit __fsblkcnt_t and __fsfilcnt_t types on 32-bit hosts.
> > * sysdeps/unix/sysv/linux/generic/bits/statfs.h: Likewise.
> > * sysdeps/unix/sysv/linux/generic/bits/typesizes.h: Likewise.
> > * sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h: Likewise.
> > * sysdeps/unix/sysv/linux/s390/bits/typesizes.h: Likewise.
> > * sysdeps/unix/sysv/linux/sparc/bits/typesizes.h: Likewise.
> > * sysdeps/unix/sysv/linux/x86/bits/typesizes.h: Likewise.
>
> Note that you no longer need to write ChangeLog entries.
>
> I don't follow the logic for which bits/typesizes.h headers you're
> updating. You're updating some for architectures not using linux/generic,
> which I think is the right thing to do - make them provide the defined
> API, whether or not they currently use any code that actually tests the
> __STATFS_MATCHES_STATFS64 macro. But you're not updating
> sysdeps/unix/sysv/linux/alpha/bits/typesizes.h or
> sysdeps/mach/hurd/bits/typesizes.h; I'd expect those to be updated as well
> for consistency.
I just missed those two, I have updated them.
Alistair
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-10-18 21:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16 23:48 [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Alistair Francis
2019-10-16 23:48 ` [PATCH v4 2/2] Define __STATFS_MATCHES_STATFS64 Alistair Francis
2019-10-18 15:13 ` Joseph Myers
2019-10-18 21:29 ` Alistair Francis
2019-10-18 15:08 ` [PATCH v4 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Joseph Myers
2019-10-18 21:25 ` Alistair Francis
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 read-only IMAP folder(s) and NNTP newsgroup(s).