小编Jez*_*Jez的帖子

获取主编号为 0 的设备(btrfs 子卷)

当我在 btrfs 子卷上统计文件时,我得到的主要设备编号为0. 有没有一种可靠的方法来找到这个设备的挂载点,而无需事先知道它是一个 btrfs 子卷?

例如,我希望能够在 python 中做到这一点:

>>> st = os.stat('a file')
>>> os.major(st.st_dev)
0
>>> os.minor(st.st_dev)
38
>>> os.path.exists('/sys/dev/block/0:38')
False
>>> magic_method_that_gets_mount_point(0, 38)
'/home'
>>> magic_method_that_gets_mount_point(8, 1)
'/boot'
Run Code Online (Sandbox Code Playgroud)

(在我的情况下,sda1( /sys/dev/block/8:1) 安装在 上/boot,并且/home是 的 btrfs 子卷sda2)。

编辑

我需要能够在不知道文件路径的情况下执行此操作。上面我用作os.stat示例,但是信息实际上是从ioctl对循环设备的调用中检索的,该循环设备返回:

struct loop_info64 {
    uint64_t    lo_device;
    uint64_t    lo_inode;
    uint64_t    lo_rdevice;
    uint64_t    lo_offset;
    uint64_t    lo_sizelimit;
    uint32_t    lo_number;
    uint32_t    lo_encrypt_type;
    uint32_t    lo_encrypt_key_size;
    uint32_t    lo_flags;
    uint8_t     lo_file_name[64];
    uint8_t     lo_crypt_name[64]; …
Run Code Online (Sandbox Code Playgroud)

filesystems system-calls stat btrfs

5
推荐指数
1
解决办法
680
查看次数

标签 统计

btrfs ×1

filesystems ×1

stat ×1

system-calls ×1