LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1165|回复: 3

关于内核raid10代码中的一个数据结构的问题。

[复制链接]
发表于 2007-11-6 17:04:12 | 显示全部楼层 |阅读模式
在看raid10代码的时候,对r10bio_s这个结构struct r10bio_s {
        atomic_t                remaining;
        sector_t                sector;       
        int                        sectors;
        unsigned long                state;
        mddev_t                        *mddev;
        struct bio                *master_bio;

        int                        read_slot;

        struct list_head        retry_list;
        /*
         * if the IO is in WRITE direction, then multiple bios are used,
         * one for each copy.
         * When resyncing we also use one for each copy.
         * When reconstructing, we use 2 bios, one for read, one for write.
         * We choose the number when they are allocated.
         */
        struct {
                struct bio                *bio;
                sector_t addr;
                int devnum;
        } devs[0];
};
中的成员devs[0]的作用不是很理解,有哪位大虾能给我指点一下。
发表于 2007-11-6 17:56:20 | 显示全部楼层
devs[0]是一个数组,这个数组没有分配任何的空间,这是一种奇怪的用法。你需要注意到devs[0]虽然没有分配空间,但是devs是存在的,这是一个指针。
你可以这样理解:

struct tmp {
struct bio *bio;
sector_t addr;
int devnum;
}

struct tmp *devs;
回复 支持 反对

使用道具 举报

发表于 2007-11-7 19:43:04 | 显示全部楼层
内核里面的placeholder,如果devs[0]后面还有代码,那么devs就是这些代码的头指针,否则则是这个结构体的尾指针,在"understanding the linux network" 里面的第一章有解释。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-11-15 19:30:52 | 显示全部楼层
thanks!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表