Andrey Kuznetsov
Andrey Kuznetsov

Reputation: 11830

Strange error(dereferencing pointer to incomplete type)

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);
}

error: dereferencing pointer to incomplete type

The error points to current->fs->pwd;

includes:

#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>

If I type current->fs; on 5th line gcc don't give error on this line. The problem is with pwd field.

Upvotes: 1

Views: 11777

Answers (4)

tarequeh
tarequeh

Reputation: 1819

This question is kind of stale but I ran into the same issue again trying to implement getcwd in kernel v2.6.33. Since this is the most relevant result that comes up when searched for "dereferencing pointer to incomplete type current->fs", it would be good to have the solution for future reference.

The solution is to include both of these headers:

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

Upvotes: 8

WhirlWind
WhirlWind

Reputation: 14112

http://lxr.linux.no/#linux+v2.6.33/include/linux/fs_struct.h#L11 -- this should work; current should be a pointer to struct task struct, which should contain a pointer to struct fs_struct fs, which should contain struct path pwd. Perhaps you need to include fs_struct.h so you can see the contents of struct fs_struct.

Upvotes: 2

AnT stands with Russia
AnT stands with Russia

Reputation: 320671

Well, the error message and your experiments obviously mean that current->fs is a pointer to an incomplete type. That's all there is to it. Why do you consider it "strange"?

Upvotes: -3

James Morris
James Morris

Reputation: 4955

error: dereferencing pointer to incomplete type means that you're attempting to access data within an opaque data structure. An opaque data structure is usually just a typedef in a header file (.h*), with the real definition in the implementation file (.c*) and only accessible to the implementation. This is used to hide the implementation details and only provide access to the elements via the interface API provided by the header.

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

Upvotes: 6

Related Questions