Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Feb 2001 12:37:06 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc:        John Baldwin <jhb@FreeBSD.org>, "Pierre Y. Dampure" <pierre.dampure@westmarsh.com>, cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org
Subject:   Re: cvs commit: src/sys/sys user.h 
Message-ID:  <Pine.BSF.4.21.0102211220350.24536-100000@besplex.bde.org>
In-Reply-To: <95465.982704647@critter>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 20 Feb 2001, Poul-Henning Kamp wrote:

> I think that a simple version number will be sufficient and that a sizeof
> will be convenient.  I don't think the sizeof should be a #define like
> now, but rather an actual sizeof().
> 
> The current #define SIZEOF is unlikely to work on Bruce's i386/64bit-long
> kernel for instance.

sizeof() on the whole struct doesn't work because it is the size of the
whole struct (and layout of the used parts).

I use the following to fix a related problem (and some tab lossage)
in struct statfs:

---
diff -c2 mount.h~ mount.h
*** mount.h~	Tue Feb 20 01:18:48 2001
--- mount.h	Tue Feb 20 01:18:51 2001
***************
*** 63,73 ****
  
  #define MFSNAMELEN	16	/* length of fs type name, including null */
! #ifdef __i386__
! #define	MNAMELEN	80	/* length of buffer for returned name */
! #endif
! #if defined(__alpha__) || defined(__ia64__)
! #define	MNAMELEN	72	/* length of buffer for returned name */
! #endif
  
  struct statfs {
  	long	f_spare2;		/* placeholder */
--- 63,70 ----
  
  #define MFSNAMELEN	16	/* length of fs type name, including null */
! #define	MNAMELEN	(88 - 2 * sizeof(long))	/* size of on/from name bufs */
  
+ /* XXX getfsstat.2 is out of date with write and read counter changes here. */
+ /* XXX statfs.2 is out of date with read counter changes here. */
  struct statfs {
  	long	f_spare2;		/* placeholder */
***************
*** 83,96 ****
  	int	f_type;			/* type of filesystem */
  	int	f_flags;		/* copy of mount exported flags */
! 	long    f_syncwrites;		/* count of sync writes since mount */
! 	long    f_asyncwrites;		/* count of async writes since mount */
  	char	f_fstypename[MFSNAMELEN]; /* fs type name */
  	char	f_mntonname[MNAMELEN];	/* directory on which mounted */
! 	long    f_syncreads;		/* count of sync reads since mount */
! 	long    f_asyncreads;		/* count of async reads since mount */
  	short	f_spares1;		/* unused spare */
  	char	f_mntfromname[MNAMELEN];/* mounted filesystem */
  	short	f_spares2;		/* unused spare */
! 	long    f_spare[2];		/* unused spare */
  };
  
--- 80,98 ----
  	int	f_type;			/* type of filesystem */
  	int	f_flags;		/* copy of mount exported flags */
! 	long	f_syncwrites;		/* count of sync writes since mount */
! 	long	f_asyncwrites;		/* count of async writes since mount */
  	char	f_fstypename[MFSNAMELEN]; /* fs type name */
  	char	f_mntonname[MNAMELEN];	/* directory on which mounted */
! 	long	f_syncreads;		/* count of sync reads since mount */
! 	long	f_asyncreads;		/* count of async reads since mount */
  	short	f_spares1;		/* unused spare */
  	char	f_mntfromname[MNAMELEN];/* mounted filesystem */
  	short	f_spares2;		/* unused spare */
! 	/*
! 	 * XXX on machines where longs are aligned to 8-byte boundaries, there
! 	 * is an unnamed int32_t here.  This spare was after the apparent end
! 	 * of the struct until we bit off the read counters from f_mntonname.
! 	 */
! 	long	f_spare[2];		/* unused spare */
  };
  
---

I.e., spell `sizeof(long)' correctly and let the compiler calculate the
magic numbers.  This still depends on the magic that MNAMELEN is not too
small after biting off a couple of longs from it.

The corresponding fix in user.h would be to write the magic size as the
sum of the sizeof()'s of all the fields, but this would be very fragile
because there would be alignment and padding issues for all the fields.
Padding would have to be explicit.

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0102211220350.24536-100000>