Skip to content

df: rows appear in different order on each execution, but shouldn't #3086

Closed

Description

@jfinkels

Running df with no other arguments results in a different order of rows on each execution. In contrast, the GNU version of df seems to produce rows in the same order on each execution.

GNU df:

$ df | head -n 5
Filesystem                1K-blocks     Used Available Use% Mounted on
udev                        3858028        0   3858028   0% /dev
tmpfs                        782624     2112    780512   1% /run
/dev/mapper/vgubuntu-root 242791844 93491652 136897300  41% /
tmpfs                       3913120        0   3913120   0% /dev/shm
$ df | head -n 5
Filesystem                1K-blocks     Used Available Use% Mounted on
udev                        3858028        0   3858028   0% /dev
tmpfs                        782624     2112    780512   1% /run
/dev/mapper/vgubuntu-root 242791844 93491652 136897300  41% /
tmpfs                       3913120        0   3913120   0% /dev/shm

uutils df:

$ ./target/debug/df | head -n 5
Filesystem          1k-blocks         Used    Available  Use% Mounted on       
/dev/loop5           56885248     56885248            0  100% /snap/snap-store/558
/dev/nvme0n1p1      535805952     32583680    503222272    6% /boot/efi       
/dev/loop1           58327040     58327040            0  100% /snap/core18/2284
tmpfs               801406976        73728    801333248    0% /run/user/1000  
$ ./target/debug/df | head -n 5
Filesystem          1k-blocks         Used    Available  Use% Mounted on       
/dev/loop4           65011712     65011712            0  100% /snap/core20/1270
tmpfs              4007034880            0   4007034880    0% /sys/fs/cgroup  
tmpfs              4007034880            0   4007034880    0% /dev/shm        
/dev/loop0           58195968     58195968            0  100% /snap/core18/2253

Activity

  1. tertsdiepraam commented on Feb 6, 2022

    @tertsdiepraam
    Collaborator

    Do you have any idea what GNU's order is based on?

  2. jfinkels commented on Feb 7, 2022

    @jfinkels
    CollaboratorAuthor

    On my Linux machine, It seems like it is based on the order given in /proc/mounts or /etc/mtab. The uucore::fsext::read_fs_list() function reads those:

    let (file_name, f) = File::open(LINUX_MOUNTINFO)
    .map(|f| (LINUX_MOUNTINFO, f))
    .or_else(|_| File::open(LINUX_MTAB).map(|f| (LINUX_MTAB, f)))
    .expect("failed to find mount list files");
    but the df::filter_mount_list() collects them into a HashMap:
    HashMap::<String, Cell<MountInfo>>::new(),
    so the order is lost.

  3. tertsdiepraam commented on Feb 7, 2022

    @tertsdiepraam
    Collaborator

    Good to know! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions