Re: set blksize of block device

From: Lei Yang (lya755_at_ece.northwestern.edu)
Date: 10/28/04

  • Next message: Gene Heskett: "Re: Intel also needs convincing on firmware licensing."
    Date:	Wed, 27 Oct 2004 22:42:17 -0500
    To: Bijoy Thomas <bijoyjth@gwu.edu>
    
    

    Thank you very much for your reply!

    The problem is, I want to do all these stuff in kernel space. More
    specifically, I want to use them in a newbie kernel module. In this
    module, I wanna do something with a raw block device (with no
    filesystem). Below are some more questions regarding to your comments.
    Really appreciate your help!

    Lei

    Bijoy Thomas wrote:

    >You set the blocksize for block device when you format it. For e.g, when you format a device with mkfs.ext2, you specify what block size you wish to use. This gets recorded in the superblock of the device. You can see what blocksize a device is using by running the tune2fs command with the deivce as an argument.
    >
    >
    What if I don'w want to format the device with a filesystem?

    >Reading and writing a block on a device in userspace is as simple as opening the device, lseeking to the block in question and doing a read or write. Keep in mind that the filesystem blocksize has nothing to do with the blocksize for the device. The sector size for most block devices is 512 bytes. This means that the unit in which we can communicate with the device is 512bytes. However, the filesystem driver will have it own unit i.e, the blocksize. Hence, usually many sectors will fall in a block. The blocks are held in the buffer cache.The filesystem block size should be a power of 2 and less than the pagesize.
    >
    >In kernel space, reads and writes to blocks on the device are done through the function bread and block_read. Both functions are used to read blocks from a device. If you modify a block, you can set the buffer as dirty and the kernel will later write it to disk.
    >
    >
    Isn't there a bwrite similar to bread?

    >Regards,
    >Bijoy.
    >
    >
    >----- Original Message -----
    >From: Lei Yang <lya755@ece.northwestern.edu>
    >Date: Wednesday, October 27, 2004 10:25 pm
    >Subject: Re: set blksize of block device
    >
    >
    >
    >>Or in other words, is there generic routines for block devices such
    >>that
    >>we could:
    >>
    >>get (set) block size of a block device;
    >>read an existing block (e.g. block 4);
    >>write an existing block (e.g. block 5);
    >>
    >>Please help!!!!
    >>
    >>TIA
    >>Lei
    >>
    >>

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Gene Heskett: "Re: Intel also needs convincing on firmware licensing."

    Relevant Pages

    • [Patch 6/10] dm: block size bug with 64 bit devs
      ... With 32 bit sector_t the block device size _in bytes_ is also cut to ... 32 bit in __set_size when the block device is mount (a filesystem ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [RFC] userland swsusp
      ... >> No. Writing to file would trash the filesystem. ... >> then write to the block device. ... > that overkill? ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Overlay ramdisk on filesystem?
      ... > filesystem so that all new files and modified files end up in the RAM ... > disk, but old files are read from the disk. ... could be a read only block device like a cdrom too), ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)