bits/stat.h

Jakub Jelinek jakub@redhat.com
Fri Feb 8 00:23:00 GMT 2002


On Thu, Feb 07, 2002 at 11:51:03PM -0800, Ulrich Drepper wrote:
> I had to undo Jakub's patch as well.  We are back where we are
> started.  The change was not correct as can be easily seen by the fact
> that the stat and stat64 structures if _FILE_OFFSET_BITS=64 had
> different padding.  I also tried to compiel some code with such a
> patch applied to my system's include file and it failed miserably.

Can you show me what the problems were?

I've just tried attached test, with both -D_FILE_OFFSET_BITS=64 and nothing,
and for each of nothing and -fpack-struct the output was identical (minus
__alignof__ for obvious reasons). With -DOLD the output was the same too,
unless -fpack-struct was given, in which case it aborts with LFS and prints
different results without. If struct stat64 uses unsigned int __pad*, then
IMHO struct stat should do the same.
-fpack-struct is not useful anyway, since unless the user is very careful,
he'll misalign struct stat which is on several architectures SIGBUS.

	Jakub
-------------- next part --------------
#define _GNU_SOURCE
#include <sys/types.h>
#include <stddef.h>
#include <stdlib.h>

struct stat
  {
    __dev_t st_dev;			/* Device.  */
#ifdef OLD
    unsigned short int __pad1;
#else
    unsigned int __pad1;
#endif
#ifndef __USE_FILE_OFFSET64
    __ino_t st_ino;			/* File serial number.	*/
#else
    __ino_t __st_ino;			/* 32bit file serial number.	*/
#endif
    __mode_t st_mode;			/* File mode.  */
    __nlink_t st_nlink;			/* Link count.  */
    __uid_t st_uid;			/* User ID of the file's owner.	*/
    __gid_t st_gid;			/* Group ID of the file's group.*/
    __dev_t st_rdev;			/* Device number, if device.  */
#ifdef OLD
    unsigned short int __pad2;
#else
    unsigned int __pad2;
#endif
#ifndef __USE_FILE_OFFSET64
    __off_t st_size;			/* Size of file, in bytes.  */
#else
    __off64_t st_size;			/* Size of file, in bytes.  */
#endif
    __blksize_t st_blksize;		/* Optimal block size for I/O.  */

#ifndef __USE_FILE_OFFSET64
    __blkcnt_t st_blocks;		/* Number 512-byte blocks allocated. */
#else
    __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
#endif
    __time_t st_atime;			/* Time of last access.  */
    unsigned long int __unused1;
    __time_t st_mtime;			/* Time of last modification.  */
    unsigned long int __unused2;
    __time_t st_ctime;			/* Time of last status change.  */
    unsigned long int __unused3;
#ifndef __USE_FILE_OFFSET64
    unsigned long int __unused4;
    unsigned long int __unused5;
#else
    __ino64_t st_ino;			/* File serial number.	*/
#endif
  };

#ifdef __USE_LARGEFILE64
struct stat64
  {
    __dev_t st_dev;			/* Device.  */
    unsigned int __pad1;

    __ino_t __st_ino;			/* 32bit file serial number.	*/
    __mode_t st_mode;			/* File mode.  */
    __nlink_t st_nlink;			/* Link count.  */
    __uid_t st_uid;			/* User ID of the file's owner.	*/
    __gid_t st_gid;			/* Group ID of the file's group.*/
    __dev_t st_rdev;			/* Device number, if device.  */
    unsigned int __pad2;
    __off64_t st_size;			/* Size of file, in bytes.  */
    __blksize_t st_blksize;		/* Optimal block size for I/O.  */

    __blkcnt64_t st_blocks;		/* Number 512-byte blocks allocated. */
    __time_t st_atime;			/* Time of last access.  */
    unsigned long int __unused1;
    __time_t st_mtime;			/* Time of last modification.  */
    unsigned long int __unused2;
    __time_t st_ctime;			/* Time of last status change.  */
    unsigned long int __unused3;
    __ino64_t st_ino;			/* File serial number.		*/
  };
#endif

int main ()
{
#ifdef __USE_FILE_OFFSET64
  if (sizeof (struct stat) != sizeof (struct stat64))
    abort ();
  if (__alignof__ (struct stat) != __alignof__ (struct stat64))
    abort ();
#endif
  printf ("size %d %d alignof %d %d\n",
	  sizeof (struct stat), sizeof (struct stat64),
	  __alignof__ (struct stat), __alignof__ (struct stat64));
#ifdef __USE_FILE_OFFSET64
#define C(x) \
  if (offsetof (struct stat, x) != offsetof (struct stat64, x)) \
    abort (); \
  printf ("%s %d %d\n", #x, offsetof (struct stat, x), offsetof (struct stat64, x));
#else
#define C(x) \
  printf ("%s %d %d\n", #x, offsetof (struct stat, x), offsetof (struct stat64, x));
#endif
  C(st_dev)
  C(st_mode)
  C(st_nlink)
  C(st_uid)
  C(st_gid)
  C(st_rdev)
  C(st_size)
  C(st_blksize)
  C(st_blocks)
  C(st_atime)
  C(st_mtime)
  C(st_ctime)
  C(st_ino)
}


More information about the Libc-hacker mailing list