summaryrefslogtreecommitdiff
path: root/src/df.c
AgeCommit message (Collapse)Author
2015-04-13df: fix --local hanging with inaccessible remote mountsPádraig Brady
* src/df.c (filter_mount_list): With -l, avoid stating remote mounts. * init.cfg: Avoid test hangs with inaccessible remote mounts. * tests/df/no-mtab-status.sh: Skip with inaccessible remote mounts. * tests/df/skip-rootfs.sh: Likewise. * tests/df/total-verify.sh: Likewise. * NEWS: Mention the bug fix. Reported at http://bugzilla.redhat.com/1199679
2015-04-03df: fix use of uninitialized variable reported by valgrindPádraig Brady
Conditional jump or move depends on uninitialised value(s) at 0x40380C: get_field_values (df.c:840) by 0x403E16: get_dev (df.c:994) by 0x404D65: get_all_entries (df.c:1364) by 0x405926: main (df.c:1714) * src/df.c (get_dev): Initialize the fsu.fsu_bavail_top_bit_set member, when adding placeholder entries. (main): Avoid a "definitely lost" memory leak warning from valgrind, reported by Bernhard Voelker.
2015-01-31doc,maint: fix use of "i.e." in documentation and commentsBernhard Voelker
To align with all other places (and correct grammar), change all upper-case "I.E." to "I.e.". Furthermore, ensure that "i.e." is followed by a comma. Finally, ensure to use a double-space before "I.e.," at the beginning of a sentence. The following was used to change all offending uses (apart from old ChangeLog files): $ git grep -liF 'i.e.' \ | xargs sed -i \ -e 's/I\.E\./I.e./g' \ -e 's/\. \(I\.e\.\)/. \1/g' \ -e 's/\([Ii]\.e\.\)\( \)/\1,\2/g' \ -e 's/\([Ii]\.e\.\)$/\1,/g' * cfg.mk (sc_prohibit_uppercase_id_est): Add new rule. (sc_ensure_double_space_after_dot_before_id_est): Likewise. (sc_ensure_comma_after_id_est): Likewise. (old_NEWS_hash): Refresh hash via "make update-NEWS-hash". * NEWS: Change use of "id est" abbreviation via the above command. * README: Likewise. * README-prereq: Likewise. * doc/coreutils.texi: Likewise. * gl/lib/rand-isaac.c: Likewise. * gl/lib/tempname.c.diff: Likewise. * man/stdbuf.x: Likewise. * src/cat.c: Likewise. * src/copy.c: Likewise. * src/copy.h: Likewise. * src/cp.c: Likewise. * src/cut.c: Likewise. * src/dd.c: Likewise. * src/df.c: Likewise. * src/fiemap.h: Likewise. * src/longlong.h: Likewise. * src/ls.c: Likewise. * src/numfmt.c: Likewise. * src/pr.c: Likewise. * src/shred.c: Likewise. * src/shuf.c: Likewise. * src/split.c: Likewise. * tests/Coreutils.pm: Likewise. * tests/df/df-symlink.sh: Likewise. * tests/df/skip-rootfs.sh: Likewise. * tests/init.sh: Likewise. * tests/ls/color-norm.sh: Likewise. * tests/misc/basename.pl: Likewise. * tests/misc/ls-misc.pl: Likewise. * tests/misc/md5sum-bsd.sh: Likewise. * tests/misc/shred-exact.sh: Likewise. * tests/misc/sort.pl: Likewise. * tests/misc/stdbuf.sh: Likewise. * tests/misc/tac-continue.sh: Likewise. * tests/rm/r-root.sh: Likewise. * tests/tail-2/symlink.sh: Likewise.
2015-01-01maint: update all copyright year number rangesPádraig Brady
Run "make update-copyright" and then... * tests/sample-test: Adjust to use the single most recent year. * tests/du/bind-mount-dir-cycle-v2.sh: Fix case in copyright message, so that year is updated automatically in future.
2014-11-24df: only suppress remote mounts of separate exports with --totalPádraig Brady
* src/df.c (filter_mount_list): Separate remote locations are generally explicitly mounted, so list each even if they share the same remote device and thus storage. However with --total keep the suppression to give a more accurate value for the total storage available. (usage): Expand on the new implications of --total and move it in the options list according to alphabetic order. doc/coreutils.texi (df invocation): Mention that --total impacts on deduplication of remote file systems and also move location according to alphabetic order. * tests/df/skip-duplicates.sh: Add remote test cases. * NEWS: Mention the change in behavior. Reported in http://bugs.debian.org/737399 Reported in http://bugzilla.redhat.com/920806 Reported in http://bugzilla.opensuse.org/866010 Reported in http://bugzilla.opensuse.org/901905
2014-11-23df: ensure -a shows all remote file system entriesPádraig Brady
commit v8.22-125-g9d736f8 printed placeholder "-" values for device names that didn't match the preferred device name for a particular mount point. However that was seen to erroneously suppress values for aliased host names or exports, common with remote file systems. * src/df.c (me_for_dev): Rename from devname_for_dev() so that we can determine the remoteness as well as the name for the preferred mount entry. (get_dev): Don't output place holder values when both current and preferred mount entries are remote. Reported in http://bugs.debian.org/737399
2014-10-27doc: mention that df -a includes duplicate file systemsPádraig Brady
* src/df.c (usage): Mention that duplicate file systems are shown with this option, not just dummy file systems. * doc/coreutils.texi (df invocation): For the --all option, expand on the class of normally suppressed mount entries that it includes. Reported in http://bugs.debian.org/737399
2014-09-19doc: output correct --help references with --program-prefixPádraig Brady
* src/system.h (emit_ancillary_info): Take the invariant PROGRAM_NAME as a parameter, so that consistent references are made to online docs and texinfo nodes, when a --program-prefix is in place. Note the man pages don't need this fix as they're generated before the program prefix is used. * NEWS: Mention the improvements in references to online documentation.
2014-09-08maint: prefer 'return status;' to 'exit (status);' in 'main'Paul Eggert
* build-aux/gen-single-binary.sh: Don't use ATTRIBUTE_NORETURN for main functions. * src/base64.c, src/basename.c, src/cat.c, src/chcon.c, src/chgrp.c: * src/chmod.c, src/chown.c, src/chroot.c, src/cksum.c, src/comm.c: * src/cp.c, src/csplit.c, src/cut.c, src/date.c, src/dd.c, src/df.c: * src/dircolors.c, src/dirname.c, src/du.c, src/echo.c, src/env.c: * src/expand.c, src/expr.c, src/factor.c, src/fmt.c, src/fold.c: * src/getlimits.c, src/groups.c, src/head.c, src/hostid.c: * src/hostname.c, src/id.c, src/install.c, src/join.c, src/kill.c: * src/link.c, src/ln.c, src/logname.c, src/ls.c, src/make-prime-list.c: * src/md5sum.c, src/mkdir.c, src/mkfifo.c, src/mknod.c, src/mktemp.c: * src/mv.c, src/nice.c, src/nl.c, src/nohup.c, src/nproc.c: * src/numfmt.c, src/od.c, src/paste.c, src/pathchk.c, src/pinky.c: * src/pr.c, src/printenv.c, src/printf.c, src/ptx.c, src/pwd.c: * src/readlink.c, src/realpath.c, src/rm.c, src/rmdir.c, src/runcon.c: * src/seq.c, src/shred.c, src/shuf.c, src/sleep.c, src/sort.c: * src/split.c, src/stat.c, src/stdbuf.c, src/stty.c, src/sum.c: * src/sync.c, src/tac.c, src/tail.c, src/tee.c, src/timeout.c: * src/touch.c, src/tr.c, src/true.c, src/truncate.c, src/tsort.c: * src/tty.c, src/uname.c, src/unexpand.c, src/uniq.c, src/unlink.c: * src/uptime.c, src/users.c, src/wc.c, src/who.c, src/whoami.c: In 'main' functions, Prefer 'return status;' to 'exit (status);'. * src/coreutils-arch.c (_single_binary_main_uname) (_single_binary_main_arch): * src/coreutils-dir.c, src/coreutils-vdir.c (_single_binary_main_ls) (_single_binary_main_dir, _single_binary_main_vdir): Omit ATTRIBUTE_NORETURN. Return a value. * src/coreutils.c (SINGLE_BINARY_PROGRAM): Omit ATTRIBUTE_NORETURN. (launch_program): Now static. * src/dd.c (finish_up): New function. (quit, main): Use it. * src/getlimits.c (main): Return a proper exit status. * src/test.c (test_main_return): New macro. (main): Use it. * src/logname.c, src/nohup.c, src/whoami.c: Use 'error' to simplify exit status in 'main' function. * src/yes.c (main): Use 'return' rather than 'error' to exit, so that GCC doesn't suggest ATTRIBUTE_NORETURN.
2014-08-19df: improve mount point selection with inaccurate mount listPádraig Brady
v8.23 has a test failure on Fedora rawhide build servers in tests/df/skip-duplicate.sh. This was due to no '/' entry being output by df. That was due to an inaccurate /proc/mounts on the build environment as stat(/mnt/point) identified all these /proc/mounts entries as having the same device id: / rootfs / /dev/md1 /dev devtmpfs /run tmpfs /boot /dev/md0 /proc/filesystems /dev/md1 Since the device name on the right changes for a given id, that causes the entries to be continually replaced, thus resulting in no '/' entry. I'm guessing this is due to the mock environment bind mounting unneeded or sensitive items to a dummy file on the host / (/dev/md1) though have not looked into those details. So rather than relying on an accurate /proc/mounts, the attached patch takes a more conservative replacement approach and only swaps a new device entry when the mount point matches. That should handle all practical cases while also avoiding this situation. * src/df.c (filter_mount_list): Only replace entries with different device names when the mount point also matches.
2014-07-13maint: avoid an inconsequential mem leakPádraig Brady
* src/df.c (get_disk): Avoid an inconsequential mem leak spotted by coverity. Also s/duplicities/duplicates/.
2014-06-25df: report correct device in presence of eclipsed mountsPádraig Brady
* src/df.c (last_device_for_mount): A new function to identify the last device mounted for a mount point. (get_disk): Use the above to discard mount entries for a device, where a later mount entry uses a different device name than that of the user specified device. * tests/df/over-mount-device.sh: A new root test. * tests/local.mk: Reference the new test. * NEWS: Reword for all these related recent fixes. Discussed at: http://bugs.gnu.org/16539#69
2014-06-24df: look for accessible mount points for specified devicesPádraig Brady
* src/df.c (get_disk): Include whether we can access the mount dir, in the mount entry selection criteria. This handles the case where a device is (bind) mounted multiple times with the shortest mount path not being accessible, while some of the other mount points are. Discussed at: http://bugs.gnu.org/16539#63
2014-06-24df: output placeholder values for inaccessible mount pointsPádraig Brady
A system provided mount entry may be unavailable due to TOCTOU race, or if another device has been over-mounted at that position, or due to access permissions. In all these cases output "-" placeholder values rather than either producing an error, or in the over-mount case outputting values for the wrong device. * src/df.c (device_list): A new global list now updated by filter_mount_list(). (filter_mount_list): Adjust to take a parameter as to whether update the global mount list, or only the mount <-> device ID mapping. (get_dev): Use the device ID mapping to ensure we're not outputting stats for the wrong device. Also output placeholder values when we can't access a system specified mount point. (get_all_entries): Set the DEVICE_ONLY param for filter_mount_list(). (devname_for_dev): A new function to search the mount <-> dev mapping. * test/df/skip-duplicates.sh: Adjust accordingly. * NEWS: Mention the bug fixes. Discussed at: http://bugs.gnu.org/16539
2014-06-18df: use all of the last device details providedPádraig Brady
* src/df.c (filter_mount_list): Recent commit v8.22-108-g25a2c94 failed to copy file system type along with the updated device name. Therefore simply replace the existing mount entry with the current one with all the latest device details. Note the name, even if not shorter in this entry, will be replaced with a shorter name in a subsequent mount entry. * tests/df/skip-duplicates.sh: Add a test case.
2014-06-02maint: avoid compiler warnings with some assert() implementationsBen Walton
* src/df.c (get_dev): asssert() on Solaris 10 is not marked as __noreturn__ and thus the compiler may think V is uninitialized later on in the function. * THANKS.in: Remove the now committer.
2014-05-29df: use the last device name provided by the systemPádraig Brady
The device name reported for a particular mount entry may no longer be valid if the mount point was subsequently mounted on a different device. Therefore honor the order of the mount list returned by the system and use the last reported device name. * src/df.c (filter_mount_list): When discarding the current mount entry, ensure that a new device name is not also discarded. * tests/df/skip-duplicates.sh: Add a test case. Also fix a false failure in the edge case of a system with only a single file system. * NEWS: Mention the fix.
2014-05-13maint: avoid clang -Wtautological-constant-out-of-range-compare warningPádraig Brady
* src/df.c (decode_output_arg): Use only enum constants to avoid clang "warning: comparison of constant -1 with expression of type 'display_field_t' is always false"
2014-05-13df: ignore non file system entries in /proc/mountsPádraig Brady
Linux with network namespaces contains entries in /proc/mounts like: proc net:[4026532464] proc rw,nosuid,nodev,noexec,relatime 0 0 resulting in a failure to stat 'net:[...]', inducing a warning and an exit with failure status. * src/df.c (get_dev): Ignore all relative mount points. * tests/df/skip-duplicates.sh: Add an entry to test relative dirs.
2014-05-13df: fix handling of symlinks in mount listPádraig Brady
The symlink handling in commit v8.21-172-g33660b4 was incomplete in the case where there were symlinks in the mount list itself. For example, in the case where /dev/mapper/fedora-home was in the mount list and that in turn was a symlink to /dev/dm-2, we have: before> df --out=source /dev/mapper/fedora-home devtmpfs after > df --out=source /dev/mapper/fedora-home /dev/mapper/fedora-home * src/df.c (get_disk): Compare canonicalized device names from the mount list. Note we still display the non canonicalized name, even if longer, as we assume that is the most representative. * tests/df/df-symlink.sh: This could theoretically fail on some systems depending on the content of the mount list, but adjust to fail on any system where symlinks are present in the mount list for the current dir.
2014-05-13df: also deduplicate virtual file systemsPádraig Brady
* src/df.c (filter_mountlist): Remove the constraint that a '/' needs to be in the device name for a mount entry to be considered for deduplication. Virtual file systems also have storage associated with them (like tmpfs for example), and thus need to be deduplicated since they will be shown in the default df output and subject to --total processing also. * test/df/skip-duplicates.sh: Add a test to ensure we deduplicate all entries, even for virtual file systems. Also avoid possible length operations on many remote file systems in the initial check of df operation. Also avoid the assumption that "/root" is on the same file system as "/". * NEWS: Mention the change in behavior.
2014-04-16maint: df: avoid sizeof(char**) static analysis warningBernhard Voelker
* src/df.c (alloc_table_row): Use the size of char** to enlarge the table. Spotted by Coverity.
2014-03-03doc: improve df --human and --si, help and man pagePádraig Brady
* src/df.c (usage): Adjust the --human and --si descriptions to not depend on each other. Also include an example that is illustrative of the rounding, suffix, width, and localized fractions. * src/system.h (emit_size_note). Adjust so that it's obvious the description is pertaining to the input SIZE argument, and not to any sizes that might be output by df for example. Fixes http://bugs.gnu.org/16922
2014-01-02maint: update all copyright year number rangesBernhard Voelker
Run "make update-copyright", but then also run this, perl -pi -e 's/2\d\d\d-//' tests/sample-test to make that one script use the single most recent year number.
2013-12-04df: handle bind mounts when processing device nodesPádraig Brady
* src/df.c (get_disk): Use the same heuristic used in get_point() to select the shortest file system mount point, in an attempt to show the base mounted file system. * NEWS: Mention the bug fix.
2013-12-04df: dereference symlinks to disk device nodesPádraig Brady
This is so the matching for the device is done on the canonical name of the disk node, rather than on the path of the symlink. In any case the user will generally want to use the symlink target. * src/df.c (get_disk): Canonicalize the passed file, before matching against the list of mounted file system devices. Note we pass the original symlink name to the "file" output field, as the symlink target is usually available through the "source" field. * tests/df/df-symlink.sh: Test the dereferencing operation. * tests/local.mk: Mention the new test. * NEWS: Mention the fix. Reported by Ondrej Oprala
2013-12-03maint: avoid '%s' quoting notation in diagnostic messagesBernhard Voelker
Add a new rule to ensure the use of quote() instead of '%s' or `%s' in format strings of diagnostics messages. * cfg.mk (sc_prohibit_quotes_notation): Add rule. * TODO: Remove the entry regarding the '%s' notation. * src/mkfifo.c (main): Remove the offending and in this case even duplicate quoting in the format string of the error diagnostic. * src/mknod.c (main): Likewise. * src/df.c (decode_output_arg): Change two invocations of error() according to the above new rule. * src/numfmt.c: Fix numerous wrong quote notations to fit the above new rule, mostly in internal debugging diagnostic messages.
2013-11-29df: remove long-obsolescent --megabytes optionBernhard Voelker
This option has been undocumented for 12 years [1], and warned about for a year [2]. [1] commit FILEUTILS-4_1_4-23-gd177203 [2] commit v8.17-43-g453ce92 * src/df.c (MEGABYTES_OPTION): Remove. (long_options): Remove "megabytes" element. (main): In the option parsing loop, remove the MEGABYTES_OPTION case. * NEWS: Mention the change.
2013-11-27df: add --output=file to directly output specified argumentsPádraig Brady
* src/df.c (usage): Document the new 'file' --output field. (get_dev): Add a new parameter to pass the specified argument from the command line through. Use '-' if a command line parameter is not being used. * doc/coreutils.texi (df invocation): Describe the new 'file' field. * tests/df/df-output.sh: Adjust all fields test, and add a specific test for --output=file. * NEWS: Mention the new feature.
2013-08-29df: fix "blocks" translation in headerPádraig Brady
* src/df.c (get_header): Get the translation of "blocks" here, rather than just marking the string for translation. Fixes http://bugs.gnu.org/15054
2013-08-05doc: more semicolons instead of periods in option descriptionsBenno Schulenberg
Also slightly rephrase some descriptions for extra clarity, and add more consistent indentation. * src/df.c (usage): Semicolon, no final period. * src/du.c (usage): Likewise, plus indentation and clarifying words. * src/ls.c (usage): Semicolon, rephrasings, added parentheses for clarity, indentation. * src/rm.c (usage): Semicolons. * src/tail.c (usage): Adjust -f description to prefer explanatory language instead of option syntax.
2013-07-11df: reduce memory usage when filtering mount entriesAnton Ovchinnikov
Avoid Valgrind reports of "definitely lost" items and while at it, free all discarded mount entries to minimize the amount of memory used. * src/df.c (filter_mount_list): Use the newly exported free_mount_entry() from gnulib to free all mount entries as they're discarded.
2013-07-11maint: adjust indentation in df.cPádraig Brady
* src/df.c: Adjust indentation and spacing with has gotten quite out of line in a couple of places.
2013-07-09df: fix mount list processing with unstatable mount dirsPádraig Brady
* src/df.c (filter_mount_list): Initialize devlist->dev_num correctly when unable to stat() a mount point. This will avoid possible invalid deduplication done on the list due to use of uninitialized memory. * tests/df/skip-duplicates.sh: Ensure this code path is exercised. Also refactor the test to be table driven. * NEWS: Mention the bug fix.
2013-01-28df: do not treat rootfs speciallyBernhard Voelker
Like any other pseudo file system, df should show rootfs only when the -a option is specified, i.e. specifying -trootfs alone is not sufficient. As the rootfs entry is now elided by the general deduplication in filter_mount_list (commit v8.20-103-gbb116d3), all other references to rootfs can be removed again. * src/df.c (show_rootfs): Remove global variable. (ROOTFS): Remove constant. (filter_mount_list): Remove case to handle rootfs specially. (main): In the case for handling the -t option, remove setting of the show_rootfs variable. * tests/df/skip-rootfs.sh: Adapt the test case "df -t rootfs": the rootfs file system must not be printed (because no -a). * doc/coreutils.texi (df invocation): Correct the documentation about eliding mount entries: it is not the first occurrence of the the device which wins, but now rather the entry with the shortest mount point name. Also adapt the description about eliding pseudo file system types like rootfs. * NEWS (Changes in behavior): Adapt entry.
2013-01-27df: prefer fullpath entries when deduplicatingOndrej Oprala
* src/df.c (struct devlist): Add a new element for storing pointers to mount_entry structures. (devlist_head, dev_examined): Remove. (filter_mount_list): Add new function to filter out the rootfs entry (unless -trootfs is specified), and duplicities. The function favors entries with a '/' character in me_devname or those with the shortest me_mountdir string, if multiple entries fulfill the first condition. Use struct devlist to build up a list of entries already known, and finally rebuild the global mount_list. (get_all_entries): Call the above new function unless the -a option is specified. (get_dev): Remove the code for skipping rootfs and duplicities. * tests/df/skip-duplicates.sh: Add test cases. Co-authored-by: Bernhard Voelker <mail@bernhard-voelker.de>
2013-01-23maint: define usage note about mandatory args centrallyBernhard Voelker
Each program with at least one long option which is marked as 'required_argument' and which has also a short option for that option, should print a note about mandatory arguments. Define that well-known note centrally and use it rather than literal printf/fputs, and add it where it was missing. * src/system.h (emit_mandatory_arg_note): Add new function. * src/cp.c (usage): Use it rather than literal printf/fputs. * src/csplit.c, src/cut.c, src/date.c, src/df.c, src/du.c: * src/expand.c, src/fmt.c, src/fold.c, src/head.c, src/install.c: * src/kill.c, src/ln.c, src/ls.c, src/mkdir.c, src/mkfifo.c: * src/mknod.c, src/mv.c, src/nl.c, src/od.c, src/paste.c: * src/pr.c, src/ptx.c, src/shred.c, src/shuf.c, src/sort.c: * src/split.c, src/stdbuf.c, src/tac.c, src/tail.c, src/timeout.c: * src/touch.c, src/truncate.c, src/unexpand.c, src/uniq.c: Likewise. * src/base64.c (usage): Add call of the above new function because at least one long option has a required argument. * src/basename.c, src/chcon.c, src/date.c, src/env.c: * src/nice.c, src/runcon.c, src/seq.c, src/stat.c, src/stty.c: Likewise.
2013-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright", but then also run this, perl -pi -e 's/2\d\d\d-//' tests/sample-test to make that one script use the single most recent year number.
2012-12-07df: do not print duplicate entries and rootfs by defaultOndrej Oprala
* src/df.c (struct devlist): Add new struct for storing already- examined device numbers. (devlist_head): Add new store of the above type. (show_rootfs): Add new global boolean to not skip rootfs. (dev_examined): Add new function to check if the device has already been traversed. (get_dev): Filter out rootfs unless "-t rootfs" or the -a option is specified. Filter out duplicate entries by calling the above new dev_examined unless the -a option is specified. (main): Set the show_rootfs variable appropriately when the -t option is specified for rootfs. Free device list (guarded by IF_LINT). * tests/df/skip-duplicates.sh: Add test to exercise the skipping of duplicate entries. * tests/df/skip-rootfs.sh: Add test to exercise the skipping of the rootfs pseudo file system. * tests/local.mk: Add the above new tests. * NEWS (Changes in behavior): Mention the changes. * doc/coreutils.texi (df invocation): Document df's behavior about skipping rootfs and duplicate entries. Co-authored-by: Bernhard Voelker.
2012-11-22df: reorder default field list of --output optionBernhard Voelker
As the inodes information is usually not so much of interest, and some file systems including btrfs do not even provide it, reading of the full df --output is easier when the block statistic fields come just left of the last field, the mount point. * src/df.c (all_args_string): Move the inodes fields before the block fields. (usage): Likewise. * tests/df/df-output.sh: Likewise. * doc/coreutils.texi (df invocation): Likewise. Additionally, explicitly mention the default order of the --output option.
2012-11-08df: document the new --output optionBernhard Voelker
* src/df.c (usage): Add a short description of --output and its available field names for use in the optional argument. * doc/coreutils.texi (df invocation): Add the new option with more details and a few examples. * NEWS (New features): Mention the new option. (Changes in behvaior): Mention the new placeholder for fields in the "total" line.
2012-11-08df: add --output to select which fields to displayBernhard Voelker
This supports changing the order of the fields displayed, and also allows the simultaneous display of inode and block fields. src/df.c (get_dev): Factor out calling get_header to ... (main): ... here. Call print_table only if file_systems_processed. src/df.c (Displayable fields): Rename DEV_FIELD to SOURCE_FIELD. Rename TYPE_FIELD to FSTYPE_FIELD. Rename FREE_FIELD to AVAIL_FIELD. Rename MNT_FIELD to TARGET_FIELD. * src/df.c (display_field_t): Turn loose enum definition of the displayable fields into a typedef. Add the inode fields ITOTAL_FIELD, IUSED_FIELD, IAVAIL_FIELD, IPCENT_FIELD. (field_data_t): Define structure to hold the display field, the caption, the width and the alignment for each field of the above type. (field_data): Add array the values of field data for each display field. (headers, alignments, widths): Remove arrays. (columns): Add a pointer to the storage for the array of the actual output columns, i.e., fields. (ncolumns): Add counter for the current output columns. (alloc_table_row): Allocate the dynamic ncolumns value of strings. (print_table): Loop over ncolumns instead of constant NFIELDS. Rename loop variable 'field' to 'col' to avoid ambiguity with the 'field' element in the columns structure. Adjust the condition for printing the last column by comparing with the column number instead of the field name (TARGET_FIELD). Use the width and the alignment stored in the columns data. (alloc_field): Add new function to allocate a field in the columns array. (get_field_list): Add new function to fill the array of output columns for each mode. (get_header): Loop over ncolumns instead of constant NFIELDS. Rename the loop variable 'field' to 'col' to avoid ambiguity with the 'field' element in the columns structure. Remove the code for continuing the loop if the current column is the file system type and print_type is not active (which is now impossible). Store the cell in the columns store along with the new width. (get_dev): Loop over ncolumns instead of the constant NFIELDS. Rename the loop variable 'field' to 'col' to avoid ambiguity with the 'field' element in the columns structure; move the definition down to where it is used first. Add cases for the inode fields ITOTAL_FIELD, IUSED_FIELD, IAVAIL_FIELD and IPCENT_FIELD. Store the cell in the columns store along with the new width. (main): Use new get_field_list function to fill the list of output columns. * src/df.c (print_table): Instead of fputs()ing directly, apply ambsalign on the last field, too. Use the new MBA_NO_RIGHT_PAD flag for this. * src/df.c (TOTAL_OPTION): Add new enum value. (long_options): Use it for the "total" option instead of 'c'. (main): Likewise. * src/df.c (get_dev): Remove condition to copy the fstype into the FSTYPE_FIELD - based on whether print_type is non-Null. Since the introduction of get_field_list(), there are only fields added to the columns array which have to be added. * src/df.c (get_dev): Guard the summing up of the values for the grand total: only do it if we have to print the total and if the current invocation is not for processing it. * src/df.c (main): Pass a hyphen "-" for the mount point name to get_dev. (get_dev): As the mount_point is now always there, remove the condition and the else case for the TARGET_FIELD. Instead, simply copy the mount_point. All cells are now always present. Therefore, add an assertion statement if one was not. Furthermore, hide the problematic characters unconditionally. (print_table): Remove the skipping of empty cells. * tests/df/total-verify.sh: Accommodate to the new "-" in the target field of the summary line. * NEWS: Mention the change in behavior. * src/df.c (field_type_t): Add new typedef of 3 enums to distinguish between block, inode and other fields. (field_data_t): Add field_type member of the above new type. (field_data): Add default values for the above field_type, indicating whether a field contains block values, inode values or other, generic values. (field_values_t): Add this struct to store the field values, used by and factored out from get_dev to be able to define such a struct for both the inode and the block values. (get_field_values): Add this function to obtain the block values and the inode values from the file system usage, used by and factored out from get_dev. (add_to_grand_total): Add this function to sum the values of the current mount point up for the grand total, used by and factored out from get_dev. (get_dev): Move the definition of the variables fsu, buf, pct and cell down to where they are used first to give them a better scope. Factor out input_units, output_units, total, available, negate_available, available_to_root, used and negate_used into the above struct field_values_t. Factor out the mapping of the fsu values to the above variables into above function get_field_values. Factor out the summing up of the grand total values into the above function add_to_grand_total. Define block_values and inode_values of the new type and call the new get_field_values to fill them from the fsu values. Call the above function add_to_grand_total for summing up the values for the grand total. Inside the loop over all fields, define a variable 'v' to point to either the block_values or the inode_values, depending on the current field's field_type. Change the code in the cases TOTAL_FIELD/ITOTAL_FIELD, USED_FIELD/IUSED_FIELD, AVAIL_FIELD/ IAVAIL_FIELD and PCENT_FIELD/IPCENT_FIELD to use the field values where 'v' is pointing to, i.e., either the block_values or the inode_values. * src/df.c (main): Remove setting of grand_fsu.fsu_blocks in the inode_format case as this is no longer needed and would lead to wrong results once when mixed block/inode fields will be used. * src/df.c (main): Cleanup the code at the end regarding file_systems_processed to make the code clearer. * src/df.c (inode_format): Remove variable. (main): Remove initialization of the above variable. In getopts loop, directly set the header_mode to INODES_MODE instead of using the above variable. Afterwards, remove the mapping to INODES_MODE as it is already set. * src/df.c (posix_format): Move variable ... (main): ... to here. * src/df.c (print_table): Enhance the comment about 2-line format in cases where the SOURCE_FIELD exceeds 20 chars, as such behavior has been removed long ago by commit v8.10-40-g99679ff. * src/df.c (Display modes): Add OUTPUT_MODE, remove unused NMODES. (display_field_t): Remove unnecessary NFIELDS. (field_data_t): Add member 'arg' for the field name in the --output argument. Add member 'used' to remember if a field is already used in the columns array. (field_data): Add values for the above new members arg and used. (all_args_string): Add variable which represents the argument for the --output option which includes all fields. (OUTPUT_OPTION): Add enum to identify the long --output option. (long_options): Add optional-argument --output option. (alloc_field): Assert that the field is not already used. Mark the field as used. (decode_output_arg): Add function to parse the comma-separated field list passed to the --output option in order to add the appropriate fields to the columns array. (get_field_list): Add case for the new OUTPUT_MODE to add all available fields to columns in the case the --output option has been passed without any values. Use the comma-separated field list form to pass to decode_output_arg to keep the field header mapping for the OUTPUT_MODE only on one place. (main): Define format string msg_mut_excl to be used in the following checks whether the use of --output and the other option is mutually exclusive. In the getopt_long loop, add a check to the case for the -i option to issue an error message when it is used together with --output; Likewise for -T and -P. Add a new case for OUTPUT_OPTION, together with similar checks as above and eventually passing the optarg to decode_output_arg. After the getopt_long loop, consider the OUTPUT_MODE case in order not to run into -h or -P mode. * src/df.c (get_dev): Also xstrdup the dev_name, and free it afterwards to silence a valgrind warning about definitely lost memory. (main): Free the columns store to silence valgrind, guarded by the IF_LINT macro. * src/df.c (main): Pass "total" as the mount point to get_dev if the SOURCE_FIELD is not among the columns to output. * tests/df/df-output.sh: Change the test to ensure the content of the target field of the grand total line: if the source field is present, then the target should be "-", else the target field should be "target". * NEWS (Changes in behavior): Enhance the exiting NEWS entry. * doc/coreutils.texi (df invocation): Document the content of the source and target field in the grand total line. * src/df.c (main): Add another condition to the need_fs_type parameter of read_file_system_list whether the FSTYPE_FIELD is used or not. * src/df.c (get_header): Indicate the block size used, in the "size" header, when using --output without -h. * tests/df/df-output.sh: Adjust for, and add an extra test for, the new behavior.
2012-08-26df: allow translators to reorder "1K-blocks" headerNguyễn Thái Ngọc Duy
* src/df.c (get_header): Mark two "%s-%s" strings for translation and give translators a hint what each is for.
2012-08-14df: fail when the mount list is required but cannot be readBernhard Voelker
* src/df.c (main): Add conditions to fail when the mount list cannot be read: this includes the cases when a file name argument is given and any of -a, -l, -t or -x is used. * doc/coreutils.texi: Document the additional error conditions. * tests/df/no-mtab-status: Add a new test. * tests/Makefile.am: Reference the new test. * NEWS: Mention the fix.
2012-08-04df: fix exit code and error messages with --totalBernhard Voelker
When the combination of the file system options with given files or devices does not lead to output, "df --total" would exit successfully although it should not. Examples: $ df --total --type=xfs / # when / is not an XFS file system $ df --total --local -t nfs DIR # nfs is remote per se ... $ df --total -t qwerty /dev/sdb5 # typo in file system type Furthermore, "df --total" would not print the error message "no file systems processed" when the file argument does not exist or is otherwise not accessible. Example: $ df --total __not_exist__ These 2 bugs are present since --total was added by commit v6.12-166-gea2887b. * src/df.c (get_dev): Do not set file_systems_processed to true when force_fsu is true, i.e. when the row for the "total" line is processed. (main): Don't print totals unless we've processed a file system. Also only print the "no FS processed" message if there was no preceding diagnostic. * tests/df/total-unprocessed: Add a new test. * tests/Makefile.am: Reference the new test. * NEWS: Mention the fix. Improved-by: Jim Meyering
2012-07-16df: don't output control characters in a mount point namePádraig Brady
It's awkward to read and problematic for scripts when control characters like '\n' are output. Note other fields are already handled with mbsalign, which converts non printable chars to the replacement char. A caveat to note with that, is the replacement char takes a place in the field and so possibly truncates the field if it was the widest field in the records. Note a more general replacement function, that handles all printable, or non white space characters, would require more sophisticated support for various encodings, and the complexity vs benefit was not deemed beneficial enough at present. Perhaps in future a more general replacement function could be shared between the various utilities. Note <space> is unaffected in any field, which could impact scripts processing the output. However any of the number fields at least could have spaces considering `LANG=fr_FR df -B\'1`, so it's probably best to leave spaces, which also allows scripts to handle mount points with spaces without change. * src/df.c (hide_problematic_chars): Replace control chars with '?'. * tests/df/problematic-chars: Add a new root only test. * tests/Makefile.am: Reference the new test. * NEWS: Mention the fix.
2012-07-11df: warn if soon-to-be-removed --megabyte option is usedBernhard Voelker
* src/df.c (MEGABYTES_OPTION): Add enum and mark it for removal in August 2013. (long_options): Use MEGABYTES_OPTION for --megabytes option. (main): Add a case for it and issue a deprecation warning if the long form is used. Document the short -m option to exist only for BSD compatibility.
2012-01-27maint: use single copyright year rangeJim Meyering
Run "make update-copyright".
2012-01-09maint: src/*.[ch]: convert more `...' to '...'Jim Meyering
Run this (twice): git grep -E -l '`.+'\' src/*.[ch] \ |xargs perl -pi -e 's/`(.+?'\'')/'\''$1/'
2012-01-09maint: src/*.c: change remaining quotes (without embedded spaces)Jim Meyering
Run this (twice): git grep -E -l '`[^ ]+'\' src/*.c \ |xargs perl -pi -e 's/`([^ ]+'\'')/'\''$1/'