Linux kernel 包括btrfs文件系统的linux内核头

Linux kernel 包括btrfs文件系统的linux内核头,linux-kernel,filesystems,linux-device-driver,btrfs,Linux Kernel,Filesystems,Linux Device Driver,Btrfs,在我的linux内核驱动程序中,我需要将struct inode强制转换为struct btrfs\u inode。 为了做到这一点,我研究了 代码非常简单: #include "/data/kernel/linux-4.1.21-x86_64/fs/btrfs/ctree.h" #include "/data/kernel/linux-4.1.21-x86_64/fs/btrfs/btrfs_inode.h" static dev_t get_device_id_btrfs(struct in

在我的linux内核驱动程序中,我需要将struct inode强制转换为struct btrfs\u inode。
为了做到这一点,我研究了

代码非常简单:

#include "/data/kernel/linux-4.1.21-x86_64/fs/btrfs/ctree.h"
#include "/data/kernel/linux-4.1.21-x86_64/fs/btrfs/btrfs_inode.h"
static dev_t get_device_id_btrfs(struct inode* inode){
if (inode != NULL) {
    struct btrfs_inode *btrfsInode;
    btrfsInode = BTRFS_I(inode);
    if (btrfsInode != NULL && btrfsInode->root != NULL) {
        return btrfsInode->root->anon_dev;
    }
}
return 0;
}
为了进行编译,我必须在函数顶部添加标题:

#include "/data/kernel/linux-4.1.21-x86_64/fs/btrfs/ctree.h"
#include "/data/kernel/linux-4.1.21-x86_64/fs/btrfs/btrfs_inode.h"
什么问题?
我必须手动下载并包含ctree.h和btrfs_inode.h,它们不在内核头包中提供。
在我编译驱动程序的每个平台上,我都有发行版/内核版本的特定虚拟机,因此在每个虚拟机上,我通常下载包内核头文件,所有内容都可以完美编译

btrfs是在上面的内核3.0中引入的。
btrfs头不应该在那里吗? 它们是否存在于另一个包中?也许是fs头或者类似的东西


谢谢

我通过下载内核源代码包并修改makefile解决了这个问题。
此解决方案可能不被推荐,但我可以接受,因为我构建的内核驱动程序只适合我维护的某些内核/发行版。
包括以下标题:

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0)
#include <fs/btrfs/ctree.h>
#include <fs/btrfs/btrfs_inode.h>
#endif

fs/btrfs
下的标题包含btrfs驱动程序专用的API:此API仅用于驱动程序的实现。因此,您的全部目的-
我需要将struct inode转换为struct btrfs\u inode
-并不“好”,因为您试图使用他人的私有API。在这种情况下,没有通用的获取此类API的方法。suse通过调用(inode->i_op->getattr(NULL、dentry和kstat)解决了这个问题,我希望避免开销,只需执行强制转换..因此我查看了btrfs inode getattr实现。您的代码如何知道inode属于btrfs文件系统?通过检查inode的超级块类型
EXTRA_CFLAGS    +=-D__Linux -std=gnu99 -I/lib/modules/$(KERNEL_HEADERS)/source