bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug#294206: stat(1) unclear about block size


From: Paul Eggert
Subject: Re: Bug#294206: stat(1) unclear about block size
Date: Tue, 08 Feb 2005 13:56:00 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Jeroen van Wolffelaar <address@hidden> writes:

>   See http://bugs.debian.org/294206#msg17 for more information, bottom
>   line is that statvfs returns a superset of values compared to statfs,
>   and one of the extra values is f_frsize required for getting the free
>   disk space in bytes.

OK, thanks, I installed this (revised) patch into coreutils, which I
hope addresses that problem.  This supersedes my previous message
on this subject.

This introduces a new format %S to stat -f -c.  You need a kernel that
has a working statvfs and f_frsize to notice any difference between %s
and %S.  I've tested it on Solaris 8, which has such a kernel.  I'd
appreciate your testing it on a Linux libc/kernel that has this
feature (mine doesn't).

Jim, this is an incompatible change to the output of "stat -f", since
it changes the default format to output both block sizes.  I think the
change is useful, but if you think that's too drastic right now please
let me know and I'll back this change out for now.

2005-02-08  Paul Eggert  <address@hidden>

        * NEWS: Document stat -f -c %S, plus changes to default formats.
        * doc/coreutils.texi (stat invocation): Normalize terminology,
        capitalization, and sort order to match --help output.  Mention %c
        for file systems.  Add new -f -c format %S, and document %s versus %S;
        problem reported by Jeroen van Wolffelaar.
        * src/stat.c (usage): Likewise.
        (STATFS_FRSIZE): New macro.
        (print_statfs): Use it, for stat -f -c %S.
        (do_statfs): Change default formats to output %S.


Index: NEWS
===================================================================
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.267
retrieving revision 1.268
diff -p -u -r1.267 -r1.268
--- NEWS        15 Jan 2005 19:56:32 -0000      1.267
+++ NEWS        8 Feb 2005 21:37:26 -0000       1.268
@@ -26,6 +26,11 @@ GNU coreutils NEWS                      
   test now detects integer overflow when evaluating large integers,
   rather than silently wrapping around.
 
+** New features
+
+  stat -f -c %S outputs the fundamental block size (used for block counts).
+  stat -f's default output format has been changed to output this size as well.
+
 * Major changes in release 5.3.0 (2005-01-08) [unstable]
 
 ** Bug fixes
Index: doc/coreutils.texi
===================================================================
RCS file: /fetish/cu/doc/coreutils.texi,v
retrieving revision 1.239
retrieving revision 1.241
diff -p -u -r1.239 -r1.241
--- doc/coreutils.texi  10 Jan 2005 18:12:35 -0000      1.239
+++ doc/coreutils.texi  8 Feb 2005 21:38:04 -0000       1.241
@@ -9065,7 +9065,7 @@ Print the information in terse form, sui
 @cindex output format
 Use @var{format} rather than the default format.
 
-Interpreted sequences for file stat are:
+The valid format sequences for files are:
 
 @itemize @bullet
 @item %a - Access rights in octal
@@ -9074,19 +9074,19 @@ Interpreted sequences for file stat are:
 @item %B - The size in bytes of each block reported by @samp{%b}
 @item %d - Device number in decimal
 @item %D - Device number in hex
address@hidden %f - raw mode in hex
address@hidden %f - Raw mode in hex
 @item %F - File type
address@hidden %g - Group Id of owner
address@hidden %g - Group ID of owner
 @item %G - Group name of owner
 @item %h - Number of hard links
 @item %i - Inode number
 @item %n - File name
address@hidden %N - Quoted File name with dereference if symbolic link
address@hidden %N - Quoted file name with dereference if symbolic link
 @item %o - I/O block size
 @item %s - Total size, in bytes
 @item %t - Major device type in hex
 @item %T - Minor device type in hex
address@hidden %u - User Id of owner
address@hidden %u - User ID of owner
 @item %U - User name of owner
 @item %x - Time of last access
 @item %X - Time of last access as seconds since Epoch
@@ -9096,19 +9096,21 @@ Interpreted sequences for file stat are:
 @item %Z - Time of last change as seconds since Epoch
 @end itemize
 
-Interpreted sequences for file system stat are:
+The valid format sequences for file systems are:
 
 @itemize @bullet
address@hidden %n - File name
address@hidden %i - File System id in hex
address@hidden %a - Free blocks available to non-superuser
address@hidden %b - Total data blocks in file system
address@hidden %c - Total file nodes in file system
address@hidden %d - Free file nodes in file system
address@hidden %f - Free blocks in file system
address@hidden %i - File System ID in hex
 @item %l - Maximum length of file names
address@hidden %n - File name
address@hidden %s - Block size (for faster transfers)
address@hidden %S - Fundamental block size (for block counts)
 @item %t - Type in hex
 @item %T - Type in human readable form
address@hidden %b - Total data blocks in file system
address@hidden %f - Free blocks in file system
address@hidden %a - Free blocks available to non-superuser
address@hidden %s - Optimal transfer block size
address@hidden %c - Total file nodes in file system
 @end itemize
 
 @vindex TZ
Index: src/stat.c
===================================================================
RCS file: /fetish/cu/src/stat.c,v
retrieving revision 1.76
retrieving revision 1.78
diff -p -u -r1.76 -r1.78
--- src/stat.c  17 Nov 2004 03:12:06 -0000      1.76
+++ src/stat.c  8 Feb 2005 21:38:53 -0000       1.78
@@ -1,5 +1,5 @@
 /* stat.c -- display file or file system status
-   Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -65,6 +65,7 @@
 # endif
 # if STAT_STATVFS
 #  define STATFS statvfs
+#  define STATFS_FRSIZE(S) ((S)->f_frsize)
 # endif
 #else
 # define STRUCT_STATVFS struct statfs
@@ -76,6 +77,7 @@
 
 #ifndef STATFS
 # define STATFS statfs
+# define STATFS_FRSIZE(S) 0
 #endif
 
 #ifndef SB_F_NAMEMAX
@@ -347,6 +349,15 @@ print_statfs (char *pformat, char m, cha
       strcat (pformat, "lu");
       printf (pformat, (unsigned long int) (statfsbuf->f_bsize));
       break;
+    case 'S':
+      {
+       unsigned long int frsize = STATFS_FRSIZE (statfsbuf);
+       if (! frsize)
+         frsize = statfsbuf->f_bsize;
+       strcat (pformat, "lu");
+       printf (pformat, frsize);
+      }
+      break;
     case 'c':
       strcat (pformat, PRIdMAX);
       printf (pformat, (intmax_t) (statfsbuf->f_files));
@@ -577,11 +588,12 @@ do_statfs (char const *filename, bool te
   if (format == NULL)
     {
       format = (terse
-               ? "%n %i %l %t %b %f %a %s %c %d\n"
+               ? "%n %i %l %t %s %S %b %f %a %c %d\n"
                : "  File: \"%n\"\n"
                "    ID: %-8i Namelen: %-7l Type: %T\n"
-               "Blocks: Total: %-10b Free: %-10f Available: %-10a Size: %s\n"
-               "Inodes: Total: %-10c Free: %-10d\n");
+               "Block size: %-10s Fundamental block size: %S\n"
+               "Blocks: Total: %-10b Free: %-10f Available: %a\n"
+               "Inodes: Total: %-10c Free: %d\n");
     }
 
   print_it (format, filename, print_statfs, &statfsbuf);
@@ -659,38 +671,38 @@ Display file or file system status.\n\
       fputs (_("\n\
 The valid format sequences for files (without --file-system):\n\
 \n\
-  %A   Access rights in human readable form\n\
   %a   Access rights in octal\n\
-  %B   The size in bytes of each block reported by `%b'\n\
+  %A   Access rights in human readable form\n\
   %b   Number of blocks allocated (see %B)\n\
+  %B   The size in bytes of each block reported by %b\n\
 "), stdout);
       fputs (_("\
-  %D   Device number in hex\n\
   %d   Device number in decimal\n\
-  %F   File type\n\
+  %D   Device number in hex\n\
   %f   Raw mode in hex\n\
-  %G   Group name of owner\n\
+  %F   File type\n\
   %g   Group ID of owner\n\
+  %G   Group name of owner\n\
 "), stdout);
       fputs (_("\
   %h   Number of hard links\n\
   %i   Inode number\n\
-  %N   Quoted File name with dereference if symbolic link\n\
   %n   File name\n\
-  %o   IO block size\n\
+  %N   Quoted file name with dereference if symbolic link\n\
+  %o   I/O block size\n\
   %s   Total size, in bytes\n\
-  %T   Minor device type in hex\n\
   %t   Major device type in hex\n\
+  %T   Minor device type in hex\n\
 "), stdout);
       fputs (_("\
-  %U   User name of owner\n\
   %u   User ID of owner\n\
-  %X   Time of last access as seconds since Epoch\n\
+  %U   User name of owner\n\
   %x   Time of last access\n\
-  %Y   Time of last modification as seconds since Epoch\n\
+  %X   Time of last access as seconds since Epoch\n\
   %y   Time of last modification\n\
-  %Z   Time of last change as seconds since Epoch\n\
+  %Y   Time of last modification as seconds since Epoch\n\
   %z   Time of last change\n\
+  %Z   Time of last change as seconds since Epoch\n\
 \n\
 "), stdout);
 
@@ -704,12 +716,13 @@ Valid format sequences for file systems:
   %f   Free blocks in file system\n\
 "), stdout);
       fputs (_("\
-  %i   File System id in hex\n\
+  %i   File System ID in hex\n\
   %l   Maximum length of filenames\n\
   %n   File name\n\
-  %s   Optimal transfer block size\n\
-  %T   Type in human readable form\n\
+  %s   Block size (for faster transfers)\n\
+  %S   Fundamental block size (for block counts)\n\
   %t   Type in hex\n\
+  %T   Type in human readable form\n\
 "), stdout);
       printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]