hi there i’m working on a project about compiling kernel. However, i’m facing with an error which says
fork.c: In function `do_fork':
fork.c:764: request for member `list' in something not a structure or union
brief explanation: i’m using a ready linked list which is defined in kernel for every type of structure.(so i have my own data structure) Moreover, i use pre-defined functions like add,traverse,delete node for my linked list but i can’t have any progress because of this error. here you can see the header file which contains my data struct.
/* project_header.h> */
#ifndef __LINUX_PROJECT_HEADER_H
#define __LINUX_PROJECT_HEADER_H
#include <linux/linkage.h>
#include <linux/vmalloc.h>
#include <linux/list.h>
#endif
typedef struct node{
struct list_head list; /* kernel's list structure */
long int sample_pid;
}NODE;
this header file is in location include/linux directory.
this is my system call which i will use within my new kernel. and i defined projectList globally to use it in other files.
#include <linux/sample.h>
#include <linux/project_header.h>
NODE projectList;
asmlinkage void sys_sample(void){
NODE* temp;
list_for_each_entry(temp, &projectList.list, list){
printk(KERN_INFO "TEMP->PID = %ld\n", temp->project_pid);
}
return;
}
and i try to use it in fork.c which is in kernel/ directory and here you can see the sample code i add into fork.c. On the other hand, i call projectList with statement extern projectList to refer which was defined in sample.c
/* do_fork.c */
/* do_fork() function */
#include <linux/project_header.h>
#include <linux/sample.h>
extern projectList; // Call variable projectList
.
.
.
do_fork(parameters..){
struct task_struct* p;
.
.
line 759-->NODE* newNode;
line 760-->newNode = kmalloc(sizeof(*newNode), GFP_KERNEL);
line 761-->newNode->sample_pid = p->pid;
line 762-->INIT_LIST_HEAD(&newNode->list);
/* add the new node to mylist */
line 764--> list_add_tail(&(newNode->list), &(projectList.list));
.
.
.
}
i hope i been clear to you, i will be very glad if you can help me and thanks anyway
You forgot to declare the type of
projectListhere, so if the compiler is in C89 mood, it applies the “implicitint” rule. Thus yourprojectListis anintinfork.c, and not astructorunionthat has members.