c - linux内核链表中的错误

时间:2017-12-19 14:49:50

标签: c compiler-errors linked-list linux-kernel kernel

我正在使用linux内核链接列表来创建使用次要编号区分的消息槽的链接列表,每个插槽都有一个使用通道ID distingushed的通道的链接列表。 我使用了linux / list.h链表。

    struct msgSlot {
    int minor;
    struct channel* channels; //Linked list for channels
    struct list_head list; //Linked list for msg slots
};

struct channel {
    char* msg;
    int id;
    struct list_head list;
};

//static struct msgSlot msgSlotsList;
//LIST_HEAD_INIT(&msgSlotsList.list);
LIST_HEAD(msgSlotsList);

static int numOfSlots = 0;


// The message the device will give when asked
static char the_message[BUF_LEN];

//================== DEVICE FUNCTIONS ===========================
static int device_open(struct inode* inode, struct file* file) {
    unsigned long flags; // for spinlock
    printk("Invoking device_open(%p)\n", file);

    int fileExists = 0; //Used as a flag to check whether the file exists or not
    struct msgSlot *tmp;
    list_for_each_entry(tmp, &msgSlotsList.list, list)
    {
        if (tmp->minor == iminor(inode)) {
            fileExists = 1;
            break; //No need to keep looking
        }

    }

    if (fileExists == 0) { //Need to open a new file
        struct msgSlot *slot = kmalloc(sizeof(struct msgSlot), GFP_KERNEL); //Create msg slot
        slot->minor = iminor(inode);
        INIT_LIST_HEAD(&slot->list);
        list_add(&slot->list, &msgSlotsList.list); //Add to list
        //struct channel *channels = kmalloc(sizeof(struct channel), GFP_KERNEL);
        //LIST_HEAD_INIT(&channels->list);
        LIST_HEAD(channels);
        slot->channels = channels;

    }

    return SUCCESS;
}

编译代码时,我收到以下错误:

    message_slot.c:53:40: error: ‘struct list_head’ has no member named ‘list’
  list_for_each_entry(tmp, &msgSlotsList.list, list)

知道怎么解决吗?

0 个答案:

没有答案