**** Merged from HEAD ****

2000-01-20  Martin Baulig  <martin@home-of-linux.org>

	* fsusage.c (adjust_blocks): Use `u_int64_t' arguments and
	return value to avoid long int overflows on machines with large
	disks.

	* fsusage.h (struct fs_usage): Use `u_int64_t' here as well.
This commit is contained in:
Martin Baulig
2000-01-20 21:54:28 +00:00
committed by Martin Baulig
parent 64b3db2dc0
commit 23c7449898
3 changed files with 25 additions and 16 deletions

8
sysdeps/common/ChangeLog Normal file
View File

@@ -0,0 +1,8 @@
2000-01-20 Martin Baulig <martin@home-of-linux.org>
* fsusage.c (adjust_blocks): Use `u_int64_t' arguments and
return value to avoid long int overflows on machines with large
disks.
* fsusage.h (struct fs_usage): Use `u_int64_t' here as well.

View File

@@ -75,9 +75,9 @@ int safe_read ();
BLOCKS FROMSIZE-byte blocks, rounding away from zero. BLOCKS FROMSIZE-byte blocks, rounding away from zero.
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */ TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
static long static u_int64_t
adjust_blocks (blocks, fromsize, tosize) adjust_blocks (blocks, fromsize, tosize)
long blocks; u_int64_t blocks;
int fromsize, tosize; int fromsize, tosize;
{ {
if (tosize <= 0) if (tosize <= 0)
@@ -88,9 +88,9 @@ adjust_blocks (blocks, fromsize, tosize)
if (fromsize == tosize) /* e.g., from 512 to 512 */ if (fromsize == tosize) /* e.g., from 512 to 512 */
return blocks; return blocks;
else if (fromsize > tosize) /* e.g., from 2048 to 512 */ else if (fromsize > tosize) /* e.g., from 2048 to 512 */
return blocks * (fromsize / tosize); return blocks * (u_int64_t)(fromsize / tosize);
else /* e.g., from 256 to 512 */ else /* e.g., from 256 to 512 */
return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize); return (blocks + (blocks < 0 ? -1 : 1)) / (u_int64_t)(tosize / fromsize);
} }
/* Fill in the fields of FSP with information about space usage for /* Fill in the fields of FSP with information about space usage for
@@ -107,7 +107,7 @@ get_fs_usage (path, disk, fsp)
struct fs_usage *fsp; struct fs_usage *fsp;
{ {
#ifdef STAT_STATFS3_OSF1 #ifdef STAT_STATFS3_OSF1
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512) # define CONVERT_BLOCKS(B) adjust_blocks ((u_int64_t)(B), fsd.f_fsize, 512)
struct statfs fsd; struct statfs fsd;
@@ -117,7 +117,7 @@ get_fs_usage (path, disk, fsp)
#endif /* STAT_STATFS3_OSF1 */ #endif /* STAT_STATFS3_OSF1 */
#ifdef STAT_STATFS2_FS_DATA /* Ultrix */ #ifdef STAT_STATFS2_FS_DATA /* Ultrix */
# define CONVERT_BLOCKS(B) adjust_blocks ((B), 1024, 512) # define CONVERT_BLOCKS(B) adjust_blocks ((u_int64_t)(B), 1024, 512)
struct fs_data fsd; struct fs_data fsd;
@@ -136,7 +136,7 @@ get_fs_usage (path, disk, fsp)
# define SUPERBOFF (SUPERB * 512) # define SUPERBOFF (SUPERB * 512)
# endif # endif
# define CONVERT_BLOCKS(B) \ # define CONVERT_BLOCKS(B) \
adjust_blocks ((B), (fsd.s_type == Fs2b ? 1024 : 512), 512) adjust_blocks ((u_int64_t)(B), (fsd.s_type == Fs2b ? 1024 : 512), 512)
struct filsys fsd; struct filsys fsd;
int fd; int fd;
@@ -166,7 +166,7 @@ get_fs_usage (path, disk, fsp)
#endif /* STAT_READ_FILSYS */ #endif /* STAT_READ_FILSYS */
#ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */ #ifdef STAT_STATFS2_BSIZE /* 4.3BSD, SunOS 4, HP-UX, AIX */
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512) # define CONVERT_BLOCKS(B) adjust_blocks ((u_int64_t)(B), fsd.f_bsize, 512)
struct statfs fsd; struct statfs fsd;
@@ -191,7 +191,7 @@ get_fs_usage (path, disk, fsp)
#endif /* STAT_STATFS2_BSIZE */ #endif /* STAT_STATFS2_BSIZE */
#ifdef STAT_STATFS2_FSIZE /* 4.4BSD */ #ifdef STAT_STATFS2_FSIZE /* 4.4BSD */
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_fsize, 512) # define CONVERT_BLOCKS(B) adjust_blocks ((u_int64_t)(B), fsd.f_fsize, 512)
struct statfs fsd; struct statfs fsd;
@@ -202,7 +202,7 @@ get_fs_usage (path, disk, fsp)
#ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */ #ifdef STAT_STATFS4 /* SVR3, Dynix, Irix, AIX */
# if _AIX || defined(_CRAY) # if _AIX || defined(_CRAY)
# define CONVERT_BLOCKS(B) adjust_blocks ((B), fsd.f_bsize, 512) # define CONVERT_BLOCKS(B) adjust_blocks ((u_int64_t)(B), fsd.f_bsize, 512)
# ifdef _CRAY # ifdef _CRAY
# define f_bavail f_bfree # define f_bavail f_bfree
# endif # endif
@@ -227,7 +227,7 @@ get_fs_usage (path, disk, fsp)
#ifdef STAT_STATVFS /* SVR4 */ #ifdef STAT_STATVFS /* SVR4 */
# define CONVERT_BLOCKS(B) \ # define CONVERT_BLOCKS(B) \
adjust_blocks ((B), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512) adjust_blocks ((u_int64_t)(B), fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize, 512)
struct statvfs fsd; struct statvfs fsd;
@@ -289,6 +289,7 @@ glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
glibtop_init_r (&server, 0, 0); glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_fsusage)); memset (buf, 0, sizeof (glibtop_fsusage));
memset (&fsp, 0, sizeof (struct fs_usage));
if (get_fs_usage (disk, disk, &fsp)) if (get_fs_usage (disk, disk, &fsp))
return; return;

View File

@@ -18,10 +18,10 @@
/* Space usage statistics for a filesystem. Blocks are 512-byte. */ /* Space usage statistics for a filesystem. Blocks are 512-byte. */
struct fs_usage struct fs_usage
{ {
long fsu_blocks; /* Total blocks. */ u_int64_t fsu_blocks; /* Total blocks. */
long fsu_bfree; /* Free blocks available to superuser. */ u_int64_t fsu_bfree; /* Free blocks available to superuser. */
long fsu_bavail; /* Free blocks available to non-superuser. */ u_int64_t fsu_bavail; /* Free blocks available to non-superuser. */
long fsu_files; /* Total file nodes. */ u_int64_t fsu_files; /* Total file nodes. */
long fsu_ffree; /* Free file nodes. */ u_int64_t fsu_ffree; /* Free file nodes. */
}; };