O'Reilly has published tons of books over the years, so it's difficult to tell which one you are reading. Patrick McManus on Kerneltrap.org has made some comment about a similar question some time ago. Some snippets:
container_of - cast a member of a structure out to the containing structure
container_of (ptr, type, member);
The macro lets you derive * struct a from * b if you know that b is a member of struct a..
this is a good example of the strong object orientation of the kernel - without any c++
http://bec-systems.com/web/content/view/94/9/ provides the basis for a pretty clear example:
Quote:
struct device_x {
int device_x_specific_param_a;
struct bus_device bd;
};
void device_x_callback(struct bus_device * bd)
{
struct device_x * devx = container_of(bd, struct device_x, bd);
do_something (x);
}
|
As for how it works, Greg Kroah-Hartman's blog has a bookmark worthy explanation:
http://www.kroah.com/log/linux/container_of.html
Linux Archive