EmbLogic's Blog

block driver crashes on add_disk

here is the code

#include”header.h”

dev_t dev;

 

 

void bulk_request(struct request_queue *q)

{
struct request *req;

req = blk_fetch_request(q);

while (req != NULL)
{

if (req == NULL || (req->cmd_type != REQ_TYPE_FS))
{
printk (KERN_NOTICE “Skip non-CMD request\n”);
__blk_end_request_all(req, -EIO);
continue;

}

}
}

 

 

 

 

int __init start(void)
{
//int reg;

// struct request *disk;

static struct request_queue *Queue;

printk(KERN_INFO “Begin : %s\n”,__func__);

printk(KERN_INFO” HELLO KERNEL”);
sbullmajor=register_blkdev(sbullmajor,device_name);

if(sbullmajor)
{

#ifdef DEBUG

printk(KERN_INFO ” Registration Sucessful\n “);

printk(KERN_INFO”Major no is %d\n”,sbullmajor);

#endif

}
else

{

#ifdef DEBUG

printk(KERN_INFO “Registartion failed\n “);

#endif
}
sbulldev=kmalloc(sizeof(struct Sbulldev),GFP_KERNEL);

memset(sbulldev,”,sizeof(struct Sbulldev));

sbulldev->size=hardsect_size;

sbulldev->data=vmalloc(sbulldev->size);

if(sbulldev->data ==NULL )

{
#ifdef DEBUG
printk(KERN_INFO ” Memory allocation failed\n “);

#endif

}
else

{
#ifdef DEBUG

printk(KERN_INFO ” Memory allocation of block device sucessful\n “);

#endif
}

spin_lock_init(&sbulldev->lock);

#ifdef DEBUG
printk(KERN_INFO ” after spin_lock\n “);

#endif
sbulldev->gd=alloc_disk(16);

if(sbulldev->gd==NULL){ //no of minors is 1 no partioning;

#ifdef DEBUG
printk(KERN_INFO ” alloc_disk failed\n “);

#endif

goto OUT;

}

else

{
#ifdef DEBUG

printk(KERN_INFO ” alloc_disk sucessful\n “);

#endif
}
Queue=blk_init_queue(bulk_request,NULL);

blk_queue_logical_block_size(Queue,hardsect_size);

sbulldev->gd->major=sbullmajor;

#ifdef DEBUG

printk(KERN_INFO ” sbullmajor\n “);

#endif

sbulldev->gd->minors=sbullminor;
#ifdef DEBUG

printk(KERN_INFO ” sbullminor\n “);

#endif

sbulldev->gd->first_minor=1;

#ifdef DEBUG

printk(KERN_INFO ” first_minor\n “);

#endif

sbulldev->gd->fops=f_ops;

#ifdef DEBUG

printk(KERN_INFO ” file_operations\n “);

#endif

sbulldev->gd->queue=Queue;

#ifdef DEBUG

printk(KERN_INFO ” Queue\n “);

#endif

sbulldev->gd->private_data=sbulldev;

#ifdef DEBUG

printk(KERN_INFO ” private_data\n “);

#endif

strcpy(sbulldev->gd->disk_name ,”sbulla” );

#ifdef DEBUG

printk(KERN_INFO ” sbulla\n “);

#endif

set_capacity(sbulldev->gd,hardsect_size);

#ifdef DEBUG

printk(KERN_INFO ” set_capacity\n “);

#endif
add_disk(sbulldev->gd);

#ifdef DEBUG

printk(KERN_INFO ” add disk\n “);

#endif

#ifdef DEBUG

printk(KERN_INFO ” End of %s\n “,__func__);

#endif

OUT:

return -1;

 

return 0;

}
void __exit release(void)
{

//int i;

#ifdef DEBUG

printk(KERN_INFO “exit : %s\n”,__func__);

#endif
del_gendisk(sbulldev->gd);

printk(KERN_INFO ” add disk\n “);

blk_cleanup_queue(sbulldev->queue);

printk(KERN_INFO ” add disk\n “);

//put_disk(sbulldev->gd);

 
unregister_blkdev(sbullmajor,device_name);
printk(KERN_INFO “BYE KERNEL”);
}
module_init(start);

module_exit(release);

}

the driver crashes  moment insmod ./modules/lkm.ko is done…..ha i have zero bytes of home drive  does this effect

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>