From 0dccdae4510ff5603247be871e64a6119647ea2a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 5 Feb 2025 16:53:27 -0500 Subject: mtab: Use mount IDs instead of dev_t for bfs_fstype() This fixes -fstype on btrfs subvolumes, which previously reported "unknown" due to their dev_t being potentially different from the mount point. Link: https://savannah.gnu.org/bugs/?50859 Link: https://lwn.net/Articles/866582/ --- src/mtab.c | 4 ++-- tests/gnu/fstype_btrfs_subvol.out | 4 ++++ tests/gnu/fstype_btrfs_subvol.sh | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/gnu/fstype_btrfs_subvol.out create mode 100644 tests/gnu/fstype_btrfs_subvol.sh diff --git a/src/mtab.c b/src/mtab.c index 4cbb9a6..40a9885 100644 --- a/src/mtab.c +++ b/src/mtab.c @@ -256,7 +256,7 @@ static int bfs_mtab_fill_types(struct bfs_mtab *mtab) { continue; } - if (trie_set_mem(&mtab->types, &sb.dev, sizeof(sb.dev), mount->type) != 0) { + if (trie_set_mem(&mtab->types, &sb.mnt_id, sizeof(sb.mnt_id), mount->type) != 0) { goto fail; } } @@ -279,7 +279,7 @@ const char *bfs_fstype(const struct bfs_mtab *mtab, const struct bfs_stat *statb } } - const char *type = trie_get_mem(&mtab->types, &statbuf->dev, sizeof(statbuf->dev)); + const char *type = trie_get_mem(&mtab->types, &statbuf->mnt_id, sizeof(statbuf->mnt_id)); if (type) { return type; } else { diff --git a/tests/gnu/fstype_btrfs_subvol.out b/tests/gnu/fstype_btrfs_subvol.out new file mode 100644 index 0000000..8871fb9 --- /dev/null +++ b/tests/gnu/fstype_btrfs_subvol.out @@ -0,0 +1,4 @@ +mnt +mnt/file +mnt/subvol +mnt/subvol/file diff --git a/tests/gnu/fstype_btrfs_subvol.sh b/tests/gnu/fstype_btrfs_subvol.sh new file mode 100644 index 0000000..71df45c --- /dev/null +++ b/tests/gnu/fstype_btrfs_subvol.sh @@ -0,0 +1,25 @@ +# Test that -fstype works in btrfs subvolumes + +command -v btrfs &>/dev/null || skip + +cd "$TEST" + +# Make a btrfs filesystem image +truncate -s128M img +mkfs.btrfs img >&2 + +# Mount it +mkdir mnt +bfs_sudo mount img mnt || skip +defer bfs_sudo umount mnt + +# Make it owned by us +bfs_sudo chown "$(id -u):$(id -g)" mnt + +# Create a subvolume inside it +btrfs subvolume create mnt/subvol >&2 + +# Make a file in and outside the subvolume +"$XTOUCH" mnt/file mnt/subvol/file + +bfs_diff mnt -fstype btrfs -print -o -printf '%p %F\n' -- cgit v1.2.3