How can I print the list values using list.h
defined in /include/linux/list.h
?
views:
93answers:
1
+2
A:
Something like this:
struct list_head head; /* previously initialized */
struct list_head *pos;
list_for_each(pos, head)
{
your_type *elt;
elt = list_entry(pos, typeof(*elt), name_of_list_head_struct_member);
/* and print *elt! */
}
Hasturkun
2010-07-14 15:12:32
NOTE: this works on the proviso that you define `your_type` with a `list_head` as its first member. That ensures that the address of the `list_head` is the same as the address of the`your_type` structure.
torak
2010-07-14 15:18:04
@torak: this is incorrect, it doesn't matter where the list_head member is, and you can have multiple list_head structs.The reason this works is that `list_entry` uses the `container_of` macro to get the correct offset from the struct member (here `name_of_list_head_struct_member`)
Hasturkun
2010-07-14 16:17:40