unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts
@ 2019-10-03 17:41 Alistair Francis
  2019-10-03 17:41 ` [PATCH v3 2/2] Define __STATFS_MATCHES_STATFS64 Alistair Francis
  2019-10-03 20:00 ` [PATCH v3 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Joseph Myers
  0 siblings, 2 replies; 5+ messages in thread
From: Alistair Francis @ 2019-10-03 17:41 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.
---
v3:
 - Don't use brackets around the defined
v2:
 - Change to if defined instead of if == 1

 sysdeps/unix/sysv/linux/generic/bits/stat.h            | 5 ++++-
 sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h | 4 ++++
 2 files changed, 8 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..0c1850322be 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
@@ -40,7 +40,10 @@
 /* Versions of the `xmknod' interface.  */
 #define _MKNOD_VER_LINUX	0
 
-#if defined __USE_FILE_OFFSET64
+#if defined __USE_FILE_OFFSET64 || 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) 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 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.  */
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] Define __STATFS_MATCHES_STATFS64
  2019-10-03 17:41 [PATCH v3 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Alistair Francis
@ 2019-10-03 17:41 ` Alistair Francis
  2019-10-03 20:03   ` Joseph Myers
  2019-10-03 20:00 ` [PATCH v3 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Joseph Myers
  1 sibling, 1 reply; 5+ messages in thread
From: Alistair Francis @ 2019-10-03 17:41 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
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.

	* sysdeps/unix/sysv/linux/generic/bits/statfs.h: Define
	__STATFS_MATCHES_STATFS64 to handle 64-bit __fsblkcnt_t
	and t__fsfilcnt_t types on 32-bit hosts.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h: Likewise.
---
This change was tested by running user space tests for RV32 and RV64.

This patch doesn't use the new macro. The RV32 port uses the macro, this
is a preperation patch.

v2:
 - Change to if defined instead of if == 1
 - Introduce __STATFS_MATCHES_STATFS64

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

diff --git a/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index c4069aba620..8c92e5d934e 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -32,7 +32,7 @@
    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 || defined __STATFS_MATCHES_STATFS64
 # 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 66546b07ccd..b68244c94de 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 defined __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
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts
  2019-10-03 17:41 [PATCH v3 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Alistair Francis
  2019-10-03 17:41 ` [PATCH v3 2/2] Define __STATFS_MATCHES_STATFS64 Alistair Francis
@ 2019-10-03 20:00 ` Joseph Myers
  1 sibling, 0 replies; 5+ messages in thread
From: Joseph Myers @ 2019-10-03 20:00 UTC (permalink / raw
  To: Alistair Francis; +Cc: libc-alpha, alistair23

On Thu, 3 Oct 2019, Alistair Francis wrote:

> diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
> index 1565f3f8248..0c1850322be 100644
> --- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
> +++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
> @@ -40,7 +40,10 @@
>  /* Versions of the `xmknod' interface.  */
>  #define _MKNOD_VER_LINUX	0
>  
> -#if defined __USE_FILE_OFFSET64
> +#if defined __USE_FILE_OFFSET64 || 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) type64 name
>  #elif __WORDSIZE == 64

Logically it feels like this actually should be added to the __WORDSIZE == 
64 case rather than the __USE_FILE_OFFSET64, so that the type names such 
as __ino_t get used to define the fields rather than those such as 
__ino64_t.  (If that makes a difference to anything in practice, it should 
just be to what typedef name debug info says was used to declare the 
fields.)

There are actually three types involved, not two.  If there's no other 
place that needs to check whether blkcnt_t and blkcnt64_t match and so 
needs a macro for that, I suppose some convenient .c file in linux/generic 
could do

#if __INO_T_MATCHES_INO64_T
_Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t),
		"__blkcnt_t and __blkcnt64_t must match");
#endif

to make sure the build fails if anyone tries to create a broken 
configuration where some types match but not others.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] Define __STATFS_MATCHES_STATFS64
  2019-10-03 17:41 ` [PATCH v3 2/2] Define __STATFS_MATCHES_STATFS64 Alistair Francis
@ 2019-10-03 20:03   ` Joseph Myers
  2019-10-15  0:15     ` Alistair Francis
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph Myers @ 2019-10-03 20:03 UTC (permalink / raw
  To: Alistair Francis; +Cc: libc-alpha, alistair23

On Thu, 3 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.

As a new macro it would be better to use the 0/1 convention (always 
defined, at least for linux/generic configurations that need it) rather 
than undefined / defined.  A default definition can go in bits/typesizes.h 
with a comment.

> -#if defined __USE_FILE_OFFSET64
> +#if defined __USE_FILE_OFFSET64 || defined __STATFS_MATCHES_STATFS64
>  # define __field64(type, type64, name) type64 name
>  #elif __WORDSIZE == 64

As in the stat case, I think it would be best to put the "|| defined 
__STATFS_MATCHES_STATFS64" in the __WORDSIZE == 64 case not the 
__USE_FILE_OFFSET64 case.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] Define __STATFS_MATCHES_STATFS64
  2019-10-03 20:03   ` Joseph Myers
@ 2019-10-15  0:15     ` Alistair Francis
  0 siblings, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2019-10-15  0:15 UTC (permalink / raw
  To: Joseph Myers; +Cc: Alistair Francis, GNU C Library

On Thu, Oct 3, 2019 at 1:03 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Thu, 3 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.
>
> As a new macro it would be better to use the 0/1 convention (always
> defined, at least for linux/generic configurations that need it) rather
> than undefined / defined.  A default definition can go in bits/typesizes.h
> with a comment.

Ok, I have updated the patch.

>
> > -#if defined __USE_FILE_OFFSET64
> > +#if defined __USE_FILE_OFFSET64 || defined __STATFS_MATCHES_STATFS64
> >  # define __field64(type, type64, name) type64 name
> >  #elif __WORDSIZE == 64
>
> As in the stat case, I think it would be best to put the "|| defined
> __STATFS_MATCHES_STATFS64" in the __WORDSIZE == 64 case not the
> __USE_FILE_OFFSET64 case.

Done, I'll send a v4 once my tests pass.

Alistair

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-15  0:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-03 17:41 [PATCH v3 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Alistair Francis
2019-10-03 17:41 ` [PATCH v3 2/2] Define __STATFS_MATCHES_STATFS64 Alistair Francis
2019-10-03 20:03   ` Joseph Myers
2019-10-15  0:15     ` Alistair Francis
2019-10-03 20:00 ` [PATCH v3 1/2] sysdeps/stat: Handle 64-bit ino_t types on 32-bit hosts Joseph Myers

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).