【发布时间】:2017-10-24 20:09:40
【问题描述】:
我正在尝试了解内核模块的代码,该模块从内核源代码进行一些函数调用。代码在device-mapper.h。
struct dm_target_io {
struct dm_io *io;
struct dm_target *ti;
unsigned target_bio_nr;
unsigned *len_ptr;
struct bio clone;
};
static inline void *dm_per_bio_data(struct bio *bio, size_t data_size)
{
return (char *)bio - offsetof(struct dm_target_io, clone) - data_size;
}
在其他地方,在 device_mapper.h 的评论中,我们被告知“dm_per_bio_data 返回数据位置”。我不知道为什么会这样。
首先,dm_per_bio_data 接受一个结构 bio* 并减去 offsetof(struct dm_target_io, clone),这应该给出封闭 dm_target_io 结构的开始。然后,它减去data_size,它把指针指向--where?
我一直在寻找 dm_target_io 在另一个结构中声明的位置,以了解通过 data_size 减去可能会带我去哪里。到目前为止还没有这样的运气。
【问题讨论】:
标签: c struct linux-kernel linux-device-driver memory-alignment