summaryrefslogtreecommitdiff
path: root/src/df.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-12-03 23:36:02 +0000
committerPádraig Brady <P@draigBrady.com>2013-12-04 13:16:27 +0000
commit33660b4973baf66423207615bef0d277ca7a5938 (patch)
tree8cce82054a6ea8f051fe80e2270ae9087b3eb40e /src/df.c
parentec6928ddb5c5571523fadcb4b04b73ccb6fbc6b1 (diff)
downloadcoreutils-33660b4973baf66423207615bef0d277ca7a5938.tar.xz
df: dereference symlinks to disk device nodes
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
Diffstat (limited to 'src/df.c')
-rw-r--r--src/df.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/df.c b/src/df.c
index ba8ef15c8..8eabcbbaa 100644
--- a/src/df.c
+++ b/src/df.c
@@ -1056,6 +1056,11 @@ get_disk (char const *disk)
{
struct mount_entry const *me;
struct mount_entry const *best_match = NULL;
+ char const *file = disk;
+
+ char *resolved = canonicalize_file_name (disk);
+ if (resolved && resolved[0] == '/')
+ disk = resolved;
for (me = mount_list; me; me = me->me_next)
{
@@ -1063,9 +1068,11 @@ get_disk (char const *disk)
best_match = me;
}
+ free (resolved);
+
if (best_match)
{
- get_dev (best_match->me_devname, best_match->me_mountdir, disk, NULL,
+ get_dev (best_match->me_devname, best_match->me_mountdir, file, NULL,
best_match->me_type, best_match->me_dummy,
best_match->me_remote, NULL, false);
return true;