After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 125049 - libgtop should provide block size with fs-usage
libgtop should provide block size with fs-usage
Status: RESOLVED FIXED
Product: libgtop
Classification: Core
Component: general
2.0.x
Other Linux
: High normal
: ---
Assigned To: libgtop maintainers
libgtop maintainers
: 138918 (view as bug list)
Depends on:
Blocks: 125060
 
 
Reported: 2003-10-20 17:28 UTC by Ole Laursen
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Tarball (tar.gz) with patch and two extra files (5.78 KB, application/x-tar-gz)
2003-12-27 15:05 UTC, Ole Laursen
  Details
possible fix (2.05 KB, patch)
2004-03-14 13:34 UTC, Bastien Nocera
none Details | Review
Missing block_size name (1.22 KB, patch)
2004-05-06 12:14 UTC, Benoît Dejean
none Details | Review
added name for fs_usafe.block_size (1.22 KB, patch)
2004-05-10 12:13 UTC, Benoît Dejean
none Details | Review

Description Ole Laursen 2003-10-20 17:28:18 UTC
Currently, the libgtop API only provides:

  struct _glibtop_fsusage
  {
    u_int64_t	flags,
		blocks,		/* Total blocks. */
		bfree,		/* Free blocks available to superuser. */
		bavail,		/* Free blocks available to non-superuser. */
		files,		/* Total file nodes. */
		ffree;		/* Free file nodes. */
  }

But the block number is pretty useless without the size of each block! For
instance, on my laptop gnome-system-monitor incorrectly reports a 10 Gb
disk when the true size is 20 Gb disk because it assumes the block size to
be 512.

Unfortunately, there seems to be different ways of retrieving the block
size on different OSes. That's why it really should be in libgtop. I have
some code for my Hardware Monitor applet:

  #if HAVE_SYS_STATFS_H
  #include <sys/statfs.h>
  #endif

  [...]

  disk_block_size = 512;	// 512 is apparently pretty common
  
#if HAVE_SYS_STATFS_H		// with statfs we can, however, do better
  struct statfs buf;
  if (statfs(mount_dir.c_str(), &buf) == 0)
    disk_block_size = buf.f_bsize;
#endif

With the following in configure.ac:

  dnl for getting the block size
  AC_CHECK_HEADER(sys/statfs.h)

This works for GNU/Linux as least for a start (IIRC for Solaris too). I
think there is a much more complicated, portable version in the sources for
'df' in GNU Coreutils. Augmenting the fsusage structure with a block_size
field should be easy.
Comment 1 Kevin Vandersloot 2003-11-20 00:25:29 UTC
*** Bug 125060 has been marked as a duplicate of this bug. ***
Comment 2 Kevin Vandersloot 2003-11-20 00:30:03 UTC
libgtop just get's it from /proc/meminfo on linux. I'm not sure why
that would be wrong. Can you check that /proc/meminfo is incorrect?
Comment 3 Ole Laursen 2003-11-20 17:38:41 UTC
I am completely mystified. /proc/meminfo is about swap and memory
info, right? I am talking about disk usage. Disk as in disk, not disk
as in swap. :-)

I think you need to reopen bug #125060. I will post the line numbers
for the wrong code in gnome-system-monitor in there.
Comment 4 Kevin Vandersloot 2003-11-20 17:59:43 UTC
woops! Sorry about that ;)
Comment 5 Bastien Nocera 2003-12-23 01:32:47 UTC
Ole, could you cook up a patch? This would have better chance of
actually getting in here.
Comment 6 Ole Laursen 2003-12-27 15:02:29 UTC
I've looked into the issue. There was actually some code (stolen from
an old release of GNU Coreutils) to ensure that the reported no. of
blocks was normalised to a block size of 512 bytes, but apparently it
didn't work. I also don't understand why one would want to support the
notion of blocks if the block size is completely artificial.

So I've made a patch that syncs with the latest version of the code
from Coreutils (in a less intrusive manner so it should be easy to
resync if necessary), avoids the normalisation step and instead adds
the field block_size to the fsusage struct. I've tested it by
modifying one of the example programs. It seems to work - in fact it
is simply the code that is used for 'df' so it must work. :-)

It is important that it be mentioned in the release notes that this
change has occurred, because it most likely _will_ break any program
that assumes the block size to be 512 bytes. They will go from
mostly-working to mostly-not-working.

I'm attaching a tarball with a patch and two extra files (I don't know
how to get them into the patch). I do have CVS access so I can easily
commit the changes if you like them.

BTW, I had to add AM_PROG_AS to configure.in to get the build system
to work with Debian's versions of automake/autoconf.

PS: Thanks for looking after an otherwise dusty old module!
Comment 7 Ole Laursen 2003-12-27 15:05:10 UTC
Created attachment 22735 [details]
Tarball (tar.gz) with patch and two extra files
Comment 8 Kjartan Maraas 2004-03-04 21:57:53 UTC
Patch is in! Whee!
Comment 9 Bastien Nocera 2004-03-09 23:28:51 UTC
Top-notch patch Ole. Added to CVS HEAD now.

2003-12-27  Ole Laursen  <olau@hardworking.dk>
                                                                     
          
        * include/glibtop/fsusage.h: Added block_size field. (Closes:
#125049)
                                                                     
          
Comment 10 Benoît Dejean 2004-03-11 22:23:15 UTC
the size of a block is currently defined as bellow

	int	block_size;

libgtop is now using the glib, so whe should use glib integer types,
as every other libgtop struct do (most of it use guint64 and guint32.

i think block_size should stored in a guint16 because large enough and
glib compliant
Comment 11 Benoît Dejean 2004-03-12 21:29:59 UTC
same problem with uintmax_t
sysdeps/common/fsusage.[ch] and sysdeps/common/fsusage-frontend.c
Comment 12 Benoît Dejean 2004-03-13 12:52:46 UTC
and GLIBTOP_MAX_FSUSAGE hasn't been updated


+#define GLIBTOP_FSUSAGE_BLOCK_SIZE     6
                                                                     
                                       
 #define GLIBTOP_MAX_FSUSAGE            5


who has authorized the following changes ?

-    guint64 fsu_blocks;        /* Total blocks. */
-    guint64 fsu_bfree; /* Free blocks available to superuser. */
-    guint64 fsu_bavail;        /* Free blocks available to
non-superuser. */
-    guint64 fsu_files; /* Total file nodes. */
-    guint64 fsu_ffree; /* Free file nodes. */
+  int fsu_blocksize;           /* Size of a block.  */
+  uintmax_t fsu_blocks;                /* Total blocks. */
+  uintmax_t fsu_bfree;         /* Free blocks available to superuser. */
+  uintmax_t fsu_bavail;                /* Free blocks available to
non-superuser. */
+  int fsu_bavail_top_bit_set;  /* 1 if fsu_bavail represents a value
< 0.  */
+  uintmax_t fsu_files;         /* Total file nodes. */
+  uintmax_t fsu_ffree;         /* Free file nodes. */


nobody has reviewed this patch ?
Comment 13 Bastien Nocera 2004-03-14 13:34:32 UTC
Created attachment 25626 [details] [review]
possible fix
Comment 14 Bastien Nocera 2004-03-14 13:38:15 UTC
int and gint are the same thing, so we should just change the external
interfaces to use gint.
uintmax_t is pretty crappy indeed, we'll use guint64. I guess that
Ole's patch was against an older version of libgtop, and that before
2.5.x, we used uintmax_t and other stuff like that from stdint.h...
Comment 15 Bastien Nocera 2004-03-15 17:53:17 UTC
2004-03-15  Bastien Nocera  <hadess@hadess.net>
                                                                     
         
        * include/glibtop/fsusage.h: set GLIBTOP_MAX_FSUSAGE properly,
        use gint in the headers instead of int (Closes: #125049)
                                                                     
         
2004-03-15  Bastien Nocera  <hadess@hadess.net>
                                                                     
         
        * fsusage.c:
        * fsusage.h: remove use of uintmax_t
Comment 16 Benoît Dejean 2004-03-15 18:44:45 UTC
i think your patch is incomplete 

- fsusage.c still uses quite obfuscated macros with uintmax_t

then some clean up is needed:

- #include <stdint.h>, <inttypes.h>, etc are now unused and should be
removed
- struct fs_usage::fsu_bavail_top_bit_set might be a gboolean instead
of int
- libgtop use 2 redundant data types : glibtop_fsusage and struct fs_usage
Comment 17 Ole Laursen 2004-03-15 23:22:11 UTC
Perhaps I can clarify. I stole the code in fsusage.[ch] from GNU
coreutils, and as explained in README.fsusage I left them almost
unchanged and instead wrote a frontend to make it easier to sync the
code later on if needed.

The previous (buggy) version of this code was modified more to fit
into libgtop and was not later resynced, which I think is the cause of
the bug.

But it is of course your decision.
Comment 18 Bastien Nocera 2004-03-16 09:22:58 UTC
Benoit, the code wasn't committed because of problems with the CVS
server. You could at least check that the ChangeLog entries are
present in the version you're testing, that's why I paste them in the
bugs...
Comment 19 Bastien Nocera 2004-03-16 10:14:28 UTC
It's been committed now.
As Ole explained, we need to keep the changes to fsusage.[ch] to a
minimum. I think that removing the use of uintmax_t et al is enough,
and not too much work on the maintainers' side.
Comment 20 Bastien Nocera 2004-04-07 09:54:04 UTC
*** Bug 138918 has been marked as a duplicate of this bug. ***
Comment 21 Benoît Dejean 2004-05-06 12:14:04 UTC
Created attachment 27427 [details] [review]
Missing block_size name
Comment 22 Benoît Dejean 2004-05-10 12:10:41 UTC
Comment on attachment 27427 [details] [review]
Missing block_size name

oop,s i don't know why block_size is gint, 

GLIBTOP_TYPE_ULONG -> GLIBTOP_TYPE_INT
Comment 23 Benoît Dejean 2004-05-10 12:13:19 UTC
Created attachment 27535 [details] [review]
added name for fs_usafe.block_size