Re: give your comments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



it crashes the system. actually, i want to write a block of data onto a raw hard disk. i dont know what blocknr and rsector value to be given in buffer_head structure.

----- Original Message -----
From: "Gaurav Dhiman"
To: "ganesh kumar"
Subject: Re: give your comments
Date: Wed, 20 Apr 2005 16:04:11 +0530

>
> Can you explain what problem are you facing with this module ?
>
>
> On 4/20/05, ganesh kumar wrote:
> >
> >
> > hi, i have attached the module. Can any one review it and tell me what was
> > the problem in this. Basically, i am trying to write in a raw hard disk, i
> > doubt in the blocknr and brsector value. #include
> > #include
> > #include
> > #include
> > #include
> > #include
> > #define MINORBITS 8 //these two macros are used to find b_rdev value
> > #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
> > #define SIZE 512
> > #define BLK_SIZE 512
> > #define SECTOR_SIZE 512 int dataWrite(void);
> > void ioCompleteHandler(struct buffer_head *bh, int uptodate);
> > int major_no;
> > struct block_device_operations block_bdops; void
> > ioCompleteHandler(struct buffer_head *bh, int uptodate)
> > {
> > printk(KERN_INFO"Freeing the memory in completeHandler function\n");
> > mark_buffer_uptodate(bh, uptodate); kfree(bh->b_data);
> > kfree(bh);
> > printk(KERN_INFO"Memory freed in iocompleHandler function\n");
> > } int dataWrite()
> > {
> > struct buffer_head *bh;
> > char *datpot;
> > printk(KERN_INFO" For testing\n");
> > printk(KERN_INFO"size of buffer is %d\n",sizeof(struct
> > buffer_head));
> > bh=kmalloc(sizeof(struct buffer_head),GFP_KERNEL);
> > if( NULL == bh)
> > {
> > printk(KERN_INFO" kmalloc failed\n");
> > return -1 ;
> > } bh->b_next = NULL;
> > bh->b_next_free = NULL;
> > bh->b_prev_free = NULL;
> > bh->b_this_page = NULL;
> > bh->b_reqnext = NULL;
> > bh->b_pprev = NULL; set_bit (BH_Uptodate, &bh->b_state);
> > set_bit (BH_Mapped, &bh->b_state); //set if the device is mapped
> > set_bit (BH_Req, &bh->b_state);
> > set_bit (BH_Dirty, &bh->b_state); //added bh->b_size=SIZE;
> > bh->b_dev = MKDEV(8,16);
> > bh->b_blocknr= 1; //not sure
> > bh->b_rsector = bh->b_blocknr * (BLK_SIZE/SECTOR_SIZE); // not sure
> > printk(KERN_INFO"allocating buffer the data\n");
> > datpot = kmalloc(SIZE,GFP_KERNEL); if
> > (NULL == datpot)
> > {
> > printk(KERN_INFO"data memory allocation failed\n");
> > return -1;
> > } bh->b_data=datpot;
> > bh->b_page = virt_to_page(bh->b_data);
> > printk(KERN_INFO"virtual to page done\n");
> > bh->b_rdev= bh->b_dev;
> > bh->b_end_io=ioCompleteHandler;
> > // bh->b_private = bh;
> > printk(KERN_INFO"calling generic make request\n");
> > generic_make_request(WRITE,bh);
> > printk(KERN_INFO" write done\n");
> > return 0;
> > } static int block_init(void)
> > {
> > int ret;
> > major_no =
> > register_blkdev(0,"block_data",&block_bdops);
> > if ( major_no <0)
> > {
> > printk(KERN_INFO"Failed to register the module\n");
> > return -1;
> > }
> > printk(KERN_INFO"Block_data Module inserted\n");
> > ret = dataWrite();
> > return 0;
> > } static void block_exit()
> > {
> > int ret;
> > ret = unregister_blkdev(major_no,"block_date");
> > if( ret < 0 )
> > {
> > printk(KERN_INFO"failed to unregister the module\n");
> > //return -1;
> > } printk(KERN_INFO"Block_data Module removed\n");
> > } module_init(block_init);
> > module_exit(block_exit);
> > MODULE_LICENSE("GPL");
> >
> > -- ___________________________________________________________
> > Sign-up for Ads Free at Mail.com
> > http://www.mail.com/?sr=signup -- Kernelnewbies: Help each other learn
> > about the Linux kernel. Archive:
> > http://mail.nl.linux.org/kernelnewbies/ FAQ:
> > http://kernelnewbies.org/faq/

--

___________________________________________________________
Sign-up for Ads Free at Mail.com
http://www.mail.com/?sr=signup

-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux