Menu

#26 df: illegal option -- x

open
nobody
None
5
2020-06-19
2018-12-07
No

xdiskusage 1.51 fails to run on macOS:

df: illegal option -- x
usage: df [-b | -H | -h | -k | -m | -g | -P] [-ailn] [-T type] [-t] [filesystem ...]

Discussion

  • Bill Spitzak

    Bill Spitzak - 2018-12-07

    Can you find out why this code at the start of xdiskusage.C does not cause the command to be the "df -k -t noprocfs,devfs,fdescfs" string?

    #if defined(DF_COMMAND)
    // assumme DU_COMMAND is also defined
    #elif defined(hpux)
    # define DF_COMMAND "df -P"
    # define DU_COMMAND "du -kx"
    #elif defined(bsdi)
    # define DF_COMMAND "df"
    # define DU_COMMAND "du -x"
    #elif defined(FreeBSD)
    # define DF_COMMAND "df -k -t noprocfs,devfs,fdescfs"
    # define DU_COMMAND "du -kx"
    #elif defined(SVR4) || defined(sun)
    # define DF_COMMAND "/bin/df -k"
    # define DU_COMMAND "/bin/du -kd"
    #else // linux
    # define DF_COMMAND "df -k -x usbfs -x tmpfs"
    # define DU_COMMAND "du -kx"
    #endif
    
     
  • Ryan Carsten Schmidt

    Ah. Well, that is not the code in version 1.51. I see that commit 275754a which added the FreeBSD part wasn't made until a year after 1.51 was released. Maybe it's time for a new release?

    If I backport that commit to 1.51, it makes no difference, because it's looking for a preprocessor define __FreeBSD__, which is not defined on macOS. If I change it to #elif defined(__FreeBSD__) || defined(__APPLE__), then the program works, to the extent that the main window appears, and I can choose a volume and get more information. However, the information in both windows does not match the information shown in the screenshots on your web site, so I don't think the correct information is being extracted from the output of the df and du commands. Note that more recent versions of macOS have more columns in their df output than earlier macOS versions did. I'm doing my tests on macOS High Sierra 10.13.6 at the moment.

     
  • Ryan Carsten Schmidt

    For example, this output is from Mac OS X 10.5:

    Filesystem    1024-blocks     Used Available Capacity  Mounted on
    /dev/disk0s3    156159792 67393780  88510012    44%    /
    fdesc                   1        1         0   100%    /dev
    map -hosts              0        0         0   100%    /net
    map auto_home           0        0         0   100%    /home
    

    And this output is from macOS 10.14:

    Filesystem    1024-blocks     Used Available Capacity iused               ifree %iused  Mounted on
    /dev/disk1s1     94167000 62324124  30123768    68% 1149569 9223372036853626238    0%   /
    /dev/disk1s4     94167000  1048600  30123768     4%       1 9223372036854775806    0%   /private/var/vm
    map -hosts              0        0         0   100%       0                   0  100%   /net
    map auto_home           0        0         0   100%       0                   0  100%   /home
    map auto_home           0        0         0   100%       0                   0  100%   /home
    
     
  • Ryan Carsten Schmidt

    man df (on macOS 10.13 High Sierra) explains why the output is now different:

         -i      Include statistics on the number of free
                 inodes. This option is now the default to
                 conform to Version 3 of the Single UNIX
                 Specification (``SUSv3'') Use -P to sup-
                 press this output.
    

    So we just need to add -P to the df flags to suppress it. But its description is:

         -P      Use (the default) 512-byte blocks.  This
                 is only useful as a way to override an
                 BLOCKSIZE specification from the environ-
                 ment.
    

    And in the legacy section of the manual it says:

         When the -P option and the -k option are used
         together, sizes are reported in 1024-blocks.  In
         legacy mode, when the -P option and -k option are
         used together, the last option specified dictates
         the reported block size.
    

    I'm not sure when legacy mode comes into effect but in case there are some situations where it does, it seems prudent to put the -P flag before the existing -k flag.

    So this is the patch I'm now using in MacPorts with xdiskusage 1.51
    (in addition to 275754a).

    It is possible that the -P flag should also be added when running df on other operating systems in case they also adopt SUSv3. I don't know if any of them do or will.

     
  • Bill Spitzak

    Bill Spitzak - 2020-06-19

    I put the -P in as suggested, but it might be better to fix the parser to skip the extra columns.

     
  • Bill Spitzak

    Bill Spitzak - 2020-06-19

    Actually it has to count from the last column because the first one (the filesystem) can have spaces in it. So probably this is the best solution.

     

Log in to post a comment.