[v2,2/2] sysdeps/statfs: Handle 64-bit ino_t types on 32-bit hosts

Message ID 20190918235448.5037-2-alistair.francis@wdc.com
State New, archived
Headers

Commit Message

Alistair Francis Sept. 18, 2019, 11:54 p.m. UTC
  On a 32-bit platform with a 64-bit ino_t type (__INO_T_MATCHES_INO64_T
defined) 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.

2019-09-16  Alistair Francis  <alistair.francis@wdc.com>

	* sysdeps/unix/sysv/linux/generic/bits/statfs.h: Handle 64-bit ino_t
	types on 32-bit hosts.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h: Likewise.
---
v2:
 - Fix the #if logic

 sysdeps/unix/sysv/linux/generic/bits/statfs.h          | 5 ++++-
 sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h | 4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)
  

Comments

Joseph Myers Sept. 19, 2019, 8:36 p.m. UTC | #1
On Wed, 18 Sep 2019, Alistair Francis wrote:

> On a 32-bit platform with a 64-bit ino_t type (__INO_T_MATCHES_INO64_T
> defined) 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.

I don't think this is anything to do with ino_t (or off_t).  It's actually 
about whether fsblkcnt_t matches fsblkcnt64_t and fsfilcnt_t matches 
fsfilcnt64_t.  It would seem cleanest for those to get their own macros 
saying whether those types match.  Or, more simply, a single macro 
__STATFS_MATCHES_STATFS64.
  
Alistair Francis Sept. 23, 2019, 11:10 p.m. UTC | #2
On Thu, Sep 19, 2019 at 1:36 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Wed, 18 Sep 2019, Alistair Francis wrote:
>
> > On a 32-bit platform with a 64-bit ino_t type (__INO_T_MATCHES_INO64_T
> > defined) 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.
>
> I don't think this is anything to do with ino_t (or off_t).  It's actually
> about whether fsblkcnt_t matches fsblkcnt64_t and fsfilcnt_t matches
> fsfilcnt64_t.  It would seem cleanest for those to get their own macros
> saying whether those types match.  Or, more simply, a single macro
> __STATFS_MATCHES_STATFS64.

That makes sense, I have updated this patch.

Alistair

>
> --
> Joseph S. Myers
> joseph@codesourcery.com
  

Patch

diff --git a/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index 3472084ade0..eab1439acff 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -32,7 +32,10 @@ 
    using __USE_FILE_OFFSET64 only see the low 32 bits of some
    of the fields (the __fsblkcnt_t and __fsfilcnt_t fields).  */
 
-#if defined __USE_FILE_OFFSET64
+#if defined(__USE_FILE_OFFSET64) || __INO_T_MATCHES_INO64_T == 1
+# if __INO_T_MATCHES_INO64_T == 1 && __OFF_T_MATCHES_OFF64_T != 1
+#  error "ino_t and off_t must both be the same type"
+# endif
 # define __field64(type, type64, name) type64 name
 #elif __WORDSIZE == 64
 # define __field64(type, type64, name) type name
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h b/sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
index 7ae01c189eb..8ac7a1da4bf 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 __INO_T_MATCHES_INO64_T
+  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
 }