Re: set blksize of block device

From: Lei Yang
Date: Wed Oct 27 2004 - 22:42:27 EST


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@xxxxxxxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/