i’m implementing a kernel module. using several techniques. 1 of them is to give read/write to different module variables. i was able to read/write all variables except the list i have in my module. the linked list:
static struct node {
struct list_head list;
unsigned int x;
struct tm time;
};
i would like to have a corresponding file in debugfs that will print the full list. i tried all the ‘simple’ read functions , but none of them actually work.. 🙁
Advertisement
Answer
You can read list using function similar to this one:
struct k_list {
struct list_head links;
int data;
};
struct k_list my_list;
static ssize_t pop_queue(struct file * file,
char *buf,
size_t count,
loff_t *ppos)
{
struct list_head *pos, *q;
struct k_list *tmp;
printk(KERN_INFO "--Listing inserted numbers--");
list_for_each_safe(pos, q, &my_list.links) {
tmp = list_entry(pos, struct k_list, links);
printk(KERN_INFO "object: %d ", tmp->data);
}
printk(KERN_INFO "--End of list--");
return count;
}