I am writing a Linux block device driver and I have a lot of the initialisation stuff working. However, when I finally call add_disk(), the module hangs during insmod.
The offending snippet is here:
set_capacity(gendisk, dev->nsectors);
add_disk(gendisk);
//this line is never reached
This appears to be caused by setting the capacity with
set_capacity()before adding the disk. According to this mailing list,add_diskshould be called on a gendisk withgendisk->capacity = 0, otherwise it hangs incheck_partition().The following appears to work: