ttjswdy 发表于 2004-4-28 17:42:46

学习过《LINUX设备驱动程序》一书的请进,请教一个问题

在《LINUX设备驱动程序》第十二章 块设备驱动程序中,讲到可分区设备 分区检测一节时,有以下一段代码(描述spull设备模块初始化时为分区检测所进行的适当设置)

    spull_sizes = kmalloc( (spull_devs << SPULL_SHIFT) * sizeof(int),
                        GFP_KERNEL);
    if (!spull_sizes)
      goto fail_malloc;

    /* Start with zero-sized partitions, and correctly sized units */
    memset(spull_sizes, 0, (spull_devs << SPULL_SHIFT) * sizeof(int));
    for (i=0; i< spull_devs; i++)
      spull_sizes = spull_size;
    blk_size = spull_gendisk.sizes = spull_sizes;

    /* Allocate the partitions array. */
    spull_partitions = kmalloc( (spull_devs << SPULL_SHIFT) *
                               sizeof(struct hd_struct), GFP_KERNEL);
    if (!spull_partitions)
      goto fail_malloc;

    memset(spull_partitions, 0, (spull_devs << SPULL_SHIFT) *
         sizeof(struct hd_struct));
    /* fill in whole-disk entries */
    for (i=0; i < spull_devs; i++)
      spull_partitions.nr_sects =
                spull_size*(blksize/SPULL_HARDSECT);
    spull_gendisk.part = spull_partitions;
    spull_gendisk.nr_real = spull_devs;
#ifndef LINUX_24
    spull_gendisk.max_nr = spull_devs;
#endif

关于这段设置spull_sizes和spull_partitions数组的代码,我有1个疑问:在这段代码内有两个for循环,分别对spull_sizes和spull_partitions数组赋值,比如说对于spull_sizes,由代码“kmalloc( (spull_devs << SPULL_SHIFT) * sizeof(int),GFP_KERNEL);”可知,spull_sizes是一个整型数组,元素为32个。(spull_devs = 2; SPULL_SHIFT = 4)。可是在FOR循环内赋值时,循环次数为2(因为spull_devs=2,即有两个spull类型的设备),对spull_sizes数组赋值时却是用"spull_sizes = spull_size;". 这样的话,岂不是只对spull_sizes和spull_sizes赋了值,那其他的元素呢?对spull_partitions数组的初始化也有这个疑问,不解呀~请教各位。
页: [1]
查看完整版本: 学习过《LINUX设备驱动程序》一书的请进,请教一个问题