public inbox for libc-ports@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: Chung-Lin Tang <cltang@codesourcery.com>
Cc: "libc-ports@sourceware.org" <libc-ports@sourceware.org>,
	Chris Metcalf <cmetcalf@tilera.com>
Subject: Re: struct statfs/statfs64 in linux-generic
Date: Mon, 04 Nov 2013 08:19:00 -0000	[thread overview]
Message-ID: <CA+=Sn1m7102-LJg8ee-ZchCaSLF1iPQKegQW6J59XS8HbX0qOg@mail.gmail.com> (raw)
In-Reply-To: <52774A2F.5010505@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 3993 bytes --]

On Sun, Nov 3, 2013 at 11:18 PM, Chung-Lin Tang <cltang@codesourcery.com> wrote:
> Hi,
>
> I'm currently working on the glibc port for Altera Nios II, and per the
> kernel upstreaming requirements, we're making it a user of linux-generic
> in glibc.
>
> I've come across an issue about struct statfs/statfs64, where I've
> listed the struct definitions in both glibc and the kernel below.
>
> In linux-generic, both struct statfs/statfs64 has some fields as 64-bit
> words, padded properly if need on 32-bit targets. Effectively, they have
> to be same-format, to pass to the statfs64 syscall uniformly.
>
> __SWORD_TYPE appears to be int/long on 32/64-bit targets. This means
> that for 32-bit targets, struct statfs[64] will be made of 32-bit words,
> with a few 64-bit fields embedded in the middle.
>
>
> In the kernel however, the fields of importance in struct statfs is made
> up of entirely '__statfs_word', defined to be 64-bit or 32-bit depending
> on target (putting aside signedness for now).
>
> Notice how that, while this does work for 64-bit targets, 32-bit targets
> cannot properly define a compatible struct statfs[64], at least not with
> simple typedefs.
>
> Chris, as you seem the original developer/maintainer of linux-generic
> and the tile ports (as I observed from the mail archives), I'm curious
> if you saw any similar problems with tilegx -m32? The only users of
> linux-generic appears to be only aarch64 and tile, and nios2 will be
> another 32-bit user.
>
> The exact FAIL I saw was posix/tst-getconf, which I traced to a failed
> statfs64 call in pathconf(), due to a failed sizeof(struct statfs64)
> check inside the kernel syscall code.


Yes I ran into this same issue when I was working on ILP32 for AARCH64.
Attached is the patch which I used.

Thanks,
Andrew Pinski

>
> Thanks,
> Chung-Lin
>
>
> In glibc, ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h:
> struct statfs
>   {
>     __SWORD_TYPE f_type;
>     __SWORD_TYPE f_bsize;
>     __field64(__fsblkcnt_t, __fsblkcnt64_t, f_blocks);
>     __field64(__fsblkcnt_t, __fsblkcnt64_t, f_bfree);
>     __field64(__fsblkcnt_t, __fsblkcnt64_t, f_bavail);
>     __field64(__fsfilcnt_t, __fsfilcnt64_t, f_files);
>     __field64(__fsfilcnt_t, __fsfilcnt64_t, f_ffree);
>     __fsid_t f_fsid;
>     __SWORD_TYPE f_namelen;
>     __SWORD_TYPE f_frsize;
>     __SWORD_TYPE f_flags;
>     __SWORD_TYPE f_spare[4];
>   } __attribute__((__aligned__(8)));
>
> #ifdef __USE_LARGEFILE64
> struct statfs64
>   {
>     __SWORD_TYPE f_type;
>     __SWORD_TYPE f_bsize;
>     __fsblkcnt64_t f_blocks;
>     __fsblkcnt64_t f_bfree;
>     __fsblkcnt64_t f_bavail;
>     __fsfilcnt64_t f_files;
>     __fsfilcnt64_t f_ffree;
>     __fsid_t f_fsid;
>     __SWORD_TYPE f_namelen;
>     __SWORD_TYPE f_frsize;
>     __SWORD_TYPE f_flags;
>     __SWORD_TYPE f_spare[4];
>   } __attribute__((__aligned__(8)));
> #endif
>
>
> In Linux kernel, include/uapi/asm-generic/statfs.h:
>
> #ifndef __statfs_word
> #if __BITS_PER_LONG == 64
> #define __statfs_word long
> #else
> #define __statfs_word __u32
> #endif
> #endif
>
> struct statfs {
>         __statfs_word f_type;
>         __statfs_word f_bsize;
>         __statfs_word f_blocks;
>         __statfs_word f_bfree;
>         __statfs_word f_bavail;
>         __statfs_word f_files;
>         __statfs_word f_ffree;
>         __kernel_fsid_t f_fsid;
>         __statfs_word f_namelen;
>         __statfs_word f_frsize;
>         __statfs_word f_flags;
>         __statfs_word f_spare[4];
> };
>
> #ifndef ARCH_PACK_STATFS64
> #define ARCH_PACK_STATFS64
> #endif
>
> struct statfs64 {
>         __statfs_word f_type;
>         __statfs_word f_bsize;
>         __u64 f_blocks;
>         __u64 f_bfree;
>         __u64 f_bavail;
>         __u64 f_files;
>         __u64 f_ffree;
>         __kernel_fsid_t f_fsid;
>         __statfs_word f_namelen;
>         __statfs_word f_frsize;
>         __statfs_word f_flags;
>         __statfs_word f_spare[4];
> } ARCH_PACK_STATFS64;

[-- Attachment #2: fixstatfs.diff.txt --]
[-- Type: text/plain, Size: 3244 bytes --]

commit 82c1e9bd5e105de7a97d29f07148da81a0349d3e
Author: Andrew Pinski <apinski@cavium.com>
Date:   Sun Aug 11 13:16:02 2013 -0700

    2013-08-11  Andrew Pinski  <apinski@cavium.com>
    
    	* ports/sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h (__FSWORD_T_TYPE): Change to
    	be __SYSCALL_SLONG_TYPE.
    	* ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h (statfs): Update to use __fsword_t.
    	(statfs64): Likewise.

diff --git a/ChangeLog.aarch64 b/ChangeLog.aarch64
index 920fb0f..bc44a2a 100644
--- a/ChangeLog.aarch64
+++ b/ChangeLog.aarch64
@@ -1,3 +1,10 @@
+2013-08-11  Andrew Pinski  <apinski@cavium.com>
+
+	* ports/sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h (__FSWORD_T_TYPE): Change to
+	be __SYSCALL_SLONG_TYPE.
+	* ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h (statfs): Update to use __fsword_t.
+	(statfs64): Likewise.
+
 2013-08-10  Andrew Pinski  <apinski@cavium.com>
 
 	* ports/sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h (__TIME_T_64_BITS): New define.
diff --git a/ports/sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h b/ports/sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h
index 74576ab..f3a51e8 100644
--- a/ports/sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h
+++ b/ports/sysdeps/unix/sysv/linux/aarch64/bits/typesizes.h
@@ -53,7 +53,7 @@
 #define	__FSBLKCNT64_T_TYPE	__UQUAD_TYPE
 #define	__FSFILCNT_T_TYPE	__ULONGWORD_TYPE
 #define	__FSFILCNT64_T_TYPE	__UQUAD_TYPE
-#define	__FSWORD_T_TYPE		__SWORD_TYPE
+#define	__FSWORD_T_TYPE		__SYSCALL_SLONG_TYPE
 #define	__ID_T_TYPE		__U32_TYPE
 #define __CLOCK_T_TYPE		__SYSCALL_SLONG_TYPE
 #define __TIME_T_TYPE		__SYSCALL_SLONG_TYPE
diff --git a/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index bf479e8..afadbf1 100644
--- a/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/ports/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -46,18 +46,18 @@
 
 struct statfs
   {
-    __SWORD_TYPE f_type;
-    __SWORD_TYPE f_bsize;
+    __fsword_t f_type;
+    __fsword_t f_bsize;
     __field64(__fsblkcnt_t, __fsblkcnt64_t, f_blocks);
     __field64(__fsblkcnt_t, __fsblkcnt64_t, f_bfree);
     __field64(__fsblkcnt_t, __fsblkcnt64_t, f_bavail);
     __field64(__fsfilcnt_t, __fsfilcnt64_t, f_files);
     __field64(__fsfilcnt_t, __fsfilcnt64_t, f_ffree);
     __fsid_t f_fsid;
-    __SWORD_TYPE f_namelen;
-    __SWORD_TYPE f_frsize;
-    __SWORD_TYPE f_flags;
-    __SWORD_TYPE f_spare[4];
+    __fsword_t f_namelen;
+    __fsword_t f_frsize;
+    __fsword_t f_flags;
+    __fsword_t f_spare[4];
   } __attribute__((__aligned__(8)));
 
 #undef __field64
@@ -65,18 +65,18 @@ struct statfs
 #ifdef __USE_LARGEFILE64
 struct statfs64
   {
-    __SWORD_TYPE f_type;
-    __SWORD_TYPE f_bsize;
+    __fsword_t f_type;
+    __fsword_t f_bsize;
     __fsblkcnt64_t f_blocks;
     __fsblkcnt64_t f_bfree;
     __fsblkcnt64_t f_bavail;
     __fsfilcnt64_t f_files;
     __fsfilcnt64_t f_ffree;
     __fsid_t f_fsid;
-    __SWORD_TYPE f_namelen;
-    __SWORD_TYPE f_frsize;
-    __SWORD_TYPE f_flags;
-    __SWORD_TYPE f_spare[4];
+    __fsword_t f_namelen;
+    __fsword_t f_frsize;
+    __fsword_t f_flags;
+    __fsword_t f_spare[4];
   } __attribute__((__aligned__(8)));
 #endif
 

  reply	other threads:[~2013-11-04  8:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04  7:18 Chung-Lin Tang
2013-11-04  8:19 ` Andrew Pinski [this message]
2013-11-05  4:23   ` Chung-Lin Tang
2013-11-07 19:55 ` Chris Metcalf
2013-11-10  8:24   ` Chung-Lin Tang
2013-11-11 17:48     ` Joseph S. Myers
2013-11-13  8:17       ` Chung-Lin Tang
2013-11-13 12:59         ` Joseph S. Myers
2013-11-14  4:34           ` Chung-Lin Tang
2013-11-14 13:36             ` Joseph S. Myers
2013-11-14 18:28             ` Chris Metcalf
2013-11-15  7:39               ` Chung-Lin Tang
2013-11-18 23:39                 ` Chris Metcalf
2013-11-19 13:50                   ` Chung-Lin Tang
2013-11-22  2:43                     ` Chris Metcalf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+=Sn1m7102-LJg8ee-ZchCaSLF1iPQKegQW6J59XS8HbX0qOg@mail.gmail.com' \
    --to=pinskia@gmail.com \
    --cc=cltang@codesourcery.com \
    --cc=cmetcalf@tilera.com \
    --cc=libc-ports@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).