Hmmm ok,

Well the reason I flagged it as a bug, is because the btrfsmaintenance package uses a script to test to see if a filesystem is btrfs and incorrectly uses stat -f to do it. This must have worked in the past else they would not use it.

The code snippet is:


# function: is_btrfs
# parameter: path to a mounted filesystem
#
# check if filesystem is a btrfs
is_btrfs() {
    local FS=$(stat -f --format=%T "$1")
    [ "$FS" = "btrfs" ] && return 0
    return 1
}


Obviously that is targeted at mounted filesystems, but the documentation and usage always shows "<path>|<device>" as a parameter.

I guess I should file a bug against that package but I am curious as to when the default behaviour changed.

Thanks for your response.

On 13/07/2023 10:59, Pádraig Brady wrote:
tag 64588 notabug
close 64588
stop

On 12/07/2023 23:46, support wrote:
coreutils version 9.1-1 on Debian testing, but also exists in previous
versions.


Example:

stat -f  /dev/sdb
    File: "/dev/sdb"
      ID: eb91af7d7bda02dd Namelen: 255     Type: tmpfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 2012292    Free: 2012292    Available: 2012292
Inodes: Total: 2012292    Free: 2011839


stat -f  /dev/disk/by-uuid/6abaa68a-2670-4d8b-8d2a-fd7321df9242
    File: "/dev/disk/by-uuid/6abaa68a-2670-4d8b-8d2a-fd7321df9242"
      ID: eb91af7d7bda02dd Namelen: 255     Type: tmpfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 2012292    Free: 2012292    Available: 2012292
Inodes: Total: 2012292    Free: 2011839


blkid /dev/sdb
/dev/sdb: UUID="6abaa68a-2670-4d8b-8d2a-fd7321df9242"
UUID_SUB="d15f1846-8f18-4ba0-9e2a-a6aaa7bbf83b" BLOCK_SIZE="4096"
TYPE="btrfs"


Not sure why the reported fstype is wrong but obviously it is a bug.

This is expected. From the info docs:

"stat does not search for specified device nodes in the file system list,
instead operating on them directly"

I.e. /dev/sdb is a device node in the /dev file system, which is tmpfs.
You can confirm this with:

  strace -e statfs stat -f -c %T /dev/sdb
  strace -e statfs df --output=fstype /dev/sdb

If you wanted to operate on a file system mounted on the device node you could:

  stat -f $(df --output=target /dev/sdb | tail -n1)

cheers,
Pádraig





Reply via email to