gpt4 book ai didi

澄清调用内核中函数的需要

转载 作者:行者123 更新时间:2023-11-30 17:12:45 24 4
gpt4 key购买 nike

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

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

下面是来自 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包含函数原型(prototype)

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

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

#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 中调用 open_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 之间的链接问题(或缺乏链接问题)造成的

提前致谢 - Rog

最佳答案

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

关于澄清调用内核中函数的需要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31302854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com