奇怪的错误(取消引用指向不完整类型的指针)

时间:2010-04-22 18:25:36

标签: c gcc linux-kernel kernel

void get_cwd(char* buf)
{
    char *result;

  current->fs->pwd;
    result = get_dentry_path(current->fs->pwd);

    memcpy(buf, result, strlen(result)+1);

    kfree(result);
}

错误:取消引用指向不完整类型的指针

错误指向current-> fs-> pwd;

包括:

#include <asm/stat.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/dirent.h>
#include <linux/sched.h>
#include <asm/uaccess.h>
#include <asm/current.h>
#include <linux/path.h>

如果我输入current-&gt; fs;在第5行gcc不会在这一行给出错误。问题出在pwd字段。

4 个答案:

答案 0 :(得分:6)

这个问题有点陈旧,但我再次尝试在内核v2.6.33中实现 getcwd 时遇到了同样的问题。由于这是搜索“解除指向不完整类型当前 - &gt; fs的指针”时出现的最相关的结果,因此最好有解决方案供将来参考。

解决方案是包含以下两个标题:

#include <linux/sched.h>
#include <linux/fs_struct.h>

答案 1 :(得分:4)

error: dereferencing pointer to incomplete type表示您尝试访问不透明数据结构中的数据。不透明的数据结构通常只是头文件(.h *)中的typedef,在实现文件(.c *)中具有真实定义,并且只能由实现访问。这用于隐藏实现细节,仅通过标头提供的接口API提供对元素的访问。

http://en.wikipedia.org/wiki/Opaque_pointer

答案 2 :(得分:2)

http://lxr.linux.no/#linux+v2.6.33/include/linux/fs_struct.h#L11 - 这应该有效; 当前应该是指向 struct task struct 的指针,该指针应包含指向 struct fs_struct fs 的指针,该指针应包含 struct path pwd 即可。也许您需要包含 fs_struct.h ,以便您可以看到 struct fs_struct 的内容。

答案 3 :(得分:-2)

嗯,错误消息和您的实验显然意味着current->fs是指向不完整类型的指针。这里的所有都是它的。为什么你认为它“奇怪”?

相关问题