【问题标题】:Clarification need on calling a function in the kernel关于在内核中调用函数的说明
【发布时间】:2015-09-26 23:09:23
【问题描述】:

我在将函数 (ext3_get_inode_loc) 调用到存在于其他几个文件中的 exec.c 中时遇到问题。

我应该提一下,我对此还很陌生,而且完全是自学的,所以我确信我有很大的知识差距。我真的很感激关于我所缺少的内容的指针或建议,和/或在哪里寻找答案。

下面是从 Linux-3.10.0.123.20.1.el7 目录递归 grep 的结果 -

"grep ext3_get_inode_loc -R *"

fs/ext3/inode.c: 
fs/ext3/inode.c:static int __ext3_get_inode_loc(struct inode *inode,  
fs/ext3/inode.c:ext3_error (inode->i_sb, ext3_get_inode_loc",  
fs/ext3/inode.c:ext3_error(inode->i_sb, ext3_get_inode_loc",  
fs/ext3/inode.c:int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc)  
fs/ext3/inode.c:return __ext3_get_inode_loc(inode, iloc,  
fs/ext3/inode.c:ret = __ext3_get_inode_loc(inode, &iloc, 0);  
fs/ext3/inode.c:err = ext3_get_inode_loc(inode, iloc);  
fs/ext3/inode.c:err = ext3_get_inode_loc(inode, &iloc);  
fs/ext3/ext3.h:extern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *);  
fs/ext3/xattr.c:error = ext3_get_inode_loc(inode, &iloc);  
fs/ext3/xattr.c:error = ext3_get_inode_loc(inode, &iloc);  
fs/ext3/xattr.c:error = ext3_get_inode_loc(inode, &is.iloc);  

这表明它仅存在于这 3 个文件中 -

ext3.h  
inode.c  
xattr.c  

ext3.h 包含函数原型

extern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *);  

inode.c 和 xattr.c 都包含 ext3.h,为这两个文件提供原型

#include "ext3.h"  

inode.c 包含函数定义 -

static int __ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc, int in_mem)
{
    ext3_fsblk_t block;
    struct buffer_head *bh;

    block = ext3_get_inode_block(inode->i_sb, inode->i_ino, iloc);
    if (!block)
            return -EIO;

    bh = sb_getblk(inode->i_sb, block);
.
.
... and so forth
}

以及函数调用本身 -

err = ext3_get_inode_loc(inode, iloc);

xattr.c 只包含调用,不包含定义 -

error = ext3_get_inode_loc(inode, &iloc);

我的问题是,如果我添加完全相同的代码行 -

error = ext3_get_inode_loc(inode, &iloc);

以与 xattr.c 相同的方式在 exec.c 中打开_exec()(没有函数定义)使用“make”编译时出现以下错误 -

fs/built-in.o: In function `open_exec':
~/linux-3.10.0-123.20.1.el7/fs/exec.c:828: undefined reference to `ext3_get_inode_loc'

为什么该函数对 xattr.c 可用,而对 exec.c 不可用?我已经对此进行了相当多的搜索,并了解到这可能是由于 exec.c 和 xattr.c 之间的链接问题(或缺少链接问题)

提前感谢 - 罗格

【问题讨论】:

  • #include ext3.h了吗?你是怎么编译的?
  • 是的,我包含了 ext3/ext.h 并正在使用源目录中的“make”进行编译,该目录在当前问题之前曾产生过可启动的运行内核。

标签: c linux function include kernel


【解决方案1】:

ext3_get_inode_loc 是本地 ext3 驱动程序,位于 fs/ext3。您不能在驱动程序代码之外调用它。

【讨论】:

    猜你喜欢
    • 2021-03-10
    • 2016-04-15
    • 2023-03-17
    • 2021-11-25
    • 2013-10-25
    • 1970-01-01
    • 1970-01-01
    • 2021-09-23
    • 2013-09-14
    相关资源
    最近更新 更多