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

And*_*sov 1 c gcc kernel linux-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);
}
Run Code Online (Sandbox Code Playgroud)

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

错误指向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>
Run Code Online (Sandbox Code Playgroud)

如果我输入current-> fs; 在第5行gcc不会在这一行给出错误.问题出在pwd现场.

tar*_*ueh 6

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

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

#include <linux/sched.h>
#include <linux/fs_struct.h>
Run Code Online (Sandbox Code Playgroud)


Jam*_*ris 5

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

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