linux-kernellinux-device-driverlinux-kernel-headers

Linux kernel 6.6 from block_device how to find out if it has mounted file system


Prior to kernel 6.6, struct block_device had member variable:

struct super_block *    bd_super;

One could check if the block device had a mounted file system or not by checking:

struct super_block *sb = bdev->bd_super;
if (!sb) {
       // block device is not mounted.
}

But from kernel 6.6., struct block_device doesnt has the member variable: bd_super. Now how to check if the block _device has a mounted file system or not?


Solution

  • After some testing I found the superblock of a file system can be accessed from block_device using below cod:

    struct super_block *sb = bdev->bd_holder;
    

    I've confirmed this with vfst, ext2,3,4, xfs file systems.