linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: set blksize of block device
@ 2004-10-28  3:34 Bijoy Thomas
  2004-10-28  3:42 ` Lei Yang
  2004-11-01 13:55 ` Jon Masters
  0 siblings, 2 replies; 14+ messages in thread
From: Bijoy Thomas @ 2004-10-28  3:34 UTC (permalink / raw)
  To: Lei Yang; +Cc: linux-kernel, kernelnewbies


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.

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.

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
> 
> 
> Lei Yang wrote:
> 
> > If nobody could answer this question, what about another one? Is 
> there 
> > a system call or a kernel interface that would allow me to write 
> a 
> > block of data to block 1 of a certain block device?
> >
> > Thanks for your reply in advance!
> >
> > Lei
> >
> > Lei Yang wrote:
> >
> >> Please cc me if you have answers to this, I am not on the list. 
> >> Thanks a lot!
> >>
> >> Lei Yang wrote:
> >>
> >>> Hello,
> >>>
> >>> I am learning block device drivers and have a newbie question. 
> Given 
> >>> a block device, is there anyway that I could set its block 
> size? For 
> >>> example, I want to write a block device driver that will work 
> on an 
> >>> existing block device.  In this driver, I want block size 
> smaller. 
> >>> (The idea looks confusing but I could explain if anybody is 
> >>> interested :- )  However,  typically the block size is 1KB, now 
> I 
> >>> want to set it to 512 or 256.  Can I do it?
> >>>
> >>> TIA
> >>> Lei
> >>>
> >>
> >>
> >>
> >
> >
> >
> > -- 
> > Kernelnewbies: Help each other learn about the Linux kernel.
> > Archive:       http://mail.nl.linux.org/kernelnewbies/
> > FAQ:           http://kernelnewbies.org/faq/
> >
> >
> 
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28  3:34 set blksize of block device Bijoy Thomas
@ 2004-10-28  3:42 ` Lei Yang
  2004-11-01 13:55 ` Jon Masters
  1 sibling, 0 replies; 14+ messages in thread
From: Lei Yang @ 2004-10-28  3:42 UTC (permalink / raw)
  To: Bijoy Thomas; +Cc: linux-kernel, kernelnewbies

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
>>    
>>



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28  3:34 set blksize of block device Bijoy Thomas
  2004-10-28  3:42 ` Lei Yang
@ 2004-11-01 13:55 ` Jon Masters
  1 sibling, 0 replies; 14+ messages in thread
From: Jon Masters @ 2004-11-01 13:55 UTC (permalink / raw)
  To: Bijoy Thomas; +Cc: Lei Yang, linux-kernel, kernelnewbies

On Wed, 27 Oct 2004 23:34:08 -0400, Bijoy Thomas <bijoyjth@gwu.edu> wrote:

> You set the blocksize for block device when you format it.

Just to clear this up for the archives, it's worth explaining the
difference between the various block sizes mentioned - the poster was
referring to hardware block size (e.g. sector size on a hard disk) and
not to the size used within a particular filesystem.

Jon.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28 21:20         ` Lei Yang
@ 2004-10-28 21:50           ` Todd Poynor
  0 siblings, 0 replies; 14+ messages in thread
From: Todd Poynor @ 2004-10-28 21:50 UTC (permalink / raw)
  To: Lei Yang; +Cc: Denis Vlasenko, linux-kernel, kernelnewbies

Lei Yang wrote:
> Denis Vlasenko wrote:
...
>> Can you use read, write and seek system calls?
...
> Not really, as I've explained, I want to do all these stuff in kernel 
> space. More specifically, I want to write a newbie kernel module. In 
> this module, I'll do something with a raw block device (with no 
> filesystem). For example, I want to do block I/O operations on ramdisk, 
> and I want to set the block size of ramdisk to whatever value I want 
> (power of 2 of course).

Pick up a copy of Linux Device Drivers by Rubini & Corbet (O'Reilly, 
2001) and start with the example ramdisk block driver in chapter 12.

-- 
Todd

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28  6:11       ` Denis Vlasenko
@ 2004-10-28 21:20         ` Lei Yang
  2004-10-28 21:50           ` Todd Poynor
  0 siblings, 1 reply; 14+ messages in thread
From: Lei Yang @ 2004-10-28 21:20 UTC (permalink / raw)
  To: Denis Vlasenko; +Cc: linux-kernel, kernelnewbies

Denis Vlasenko wrote:

>On Thursday 28 October 2004 05:25, Lei Yang wrote:
>  
>
>>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);
>>    
>>
>
>Can you stick to "reply below quote" style please?
>  
>
OK

>  
>
>>>If nobody could answer this question, what about another one? Is there 
>>>a system call or a kernel interface that would allow me to write a 
>>>      
>>>
>
>Can you use read, write and seek system calls?
>--
>vda
>
>
>  
>
Not really, as I've explained, I want to do all these stuff in kernel 
space. More specifically, I want to write a newbie kernel module. In 
this module, I'll do something with a raw block device (with no 
filesystem). For example, I want to do block I/O operations on ramdisk, 
and I want to set the block size of ramdisk to whatever value I want 
(power of 2 of course).

Any comments?

Thanks,
Lei


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28 16:35     ` Shesha B.  Sreenivasamurthy
@ 2004-10-28 21:04       ` Lei Yang
  0 siblings, 0 replies; 14+ messages in thread
From: Lei Yang @ 2004-10-28 21:04 UTC (permalink / raw)
  To: "Shesha B. " Sreenivasamurthy; +Cc: LinuxKernel Group, kernelnewbies

Shesha B. Sreenivasamurthy wrote:

>Firstly you cannot set the block size to lesser than 512. 
>
>When there is a request for the IO, you populate "struct req" data
>structure which you will pass it to the kernel or lower level SCSI/SATA
>driver. In the "struct req" there is a field "b_size" which may be what
>you are interested in. At the user level you can use the IOCTLs to set
>the block size of the RAW block device.
>
>-Shesha
>  
>
I understand that for real block device (like hard disk), block size 
cannot be less than 512. But to ramdisks, I think they are truely random 
addressable, and should be able to move on blocks even with size of 2 bytes.

Any comments?

>On Wed, 2004-10-27 at 18:44, Lei Yang wrote:
>  
>
>>If nobody could answer this question, what about another one? Is there a 
>>system call or a kernel interface that would allow me to write a block 
>>of data to block 1 of a certain block device?
>>
>>Thanks for your reply in advance!
>>
>>Lei
>>
>>Lei Yang wrote:
>>
>>    
>>
>>>Please cc me if you have answers to this, I am not on the list. Thanks 
>>>a lot!
>>>
>>>Lei Yang wrote:
>>>
>>>      
>>>
>>>>Hello,
>>>>
>>>>I am learning block device drivers and have a newbie question. Given 
>>>>a block device, is there anyway that I could set its block size? For 
>>>>example, I want to write a block device driver that will work on an 
>>>>existing block device.  In this driver, I want block size smaller. 
>>>>(The idea looks confusing but I could explain if anybody is 
>>>>interested :- )  However,  typically the block size is 1KB, now I 
>>>>want to set it to 512 or 256.  Can I do it?
>>>>
>>>>TIA
>>>>Lei
>>>>
>>>>        
>>>>
>>>
>>>      
>>>
>>
>>--
>>Kernelnewbies: Help each other learn about the Linux kernel.
>>Archive:       http://mail.nl.linux.org/kernelnewbies/
>>FAQ:           http://kernelnewbies.org/faq/
>>    
>>



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28  1:44   ` Lei Yang
  2004-10-28  2:25     ` Lei Yang
  2004-10-28  6:09     ` Denis Vlasenko
@ 2004-10-28 16:35     ` Shesha B.  Sreenivasamurthy
  2004-10-28 21:04       ` Lei Yang
  2 siblings, 1 reply; 14+ messages in thread
From: Shesha B.  Sreenivasamurthy @ 2004-10-28 16:35 UTC (permalink / raw)
  To: Lei Yang; +Cc: LinuxKernel Group, kernelnewbies

Firstly you cannot set the block size to lesser than 512. 

When there is a request for the IO, you populate "struct req" data
structure which you will pass it to the kernel or lower level SCSI/SATA
driver. In the "struct req" there is a field "b_size" which may be what
you are interested in. At the user level you can use the IOCTLs to set
the block size of the RAW block device.

-Shesha

On Wed, 2004-10-27 at 18:44, Lei Yang wrote:
> If nobody could answer this question, what about another one? Is there a 
> system call or a kernel interface that would allow me to write a block 
> of data to block 1 of a certain block device?
> 
> Thanks for your reply in advance!
> 
> Lei
> 
> Lei Yang wrote:
> 
> > Please cc me if you have answers to this, I am not on the list. Thanks 
> > a lot!
> >
> > Lei Yang wrote:
> >
> >> Hello,
> >>
> >> I am learning block device drivers and have a newbie question. Given 
> >> a block device, is there anyway that I could set its block size? For 
> >> example, I want to write a block device driver that will work on an 
> >> existing block device.  In this driver, I want block size smaller. 
> >> (The idea looks confusing but I could explain if anybody is 
> >> interested :- )  However,  typically the block size is 1KB, now I 
> >> want to set it to 512 or 256.  Can I do it?
> >>
> >> TIA
> >> Lei
> >>
> >
> >
> >
> 
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
-- 
  .-----.
 /       \
{  o | o  } 
     |
    \_/
      


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28  2:25     ` Lei Yang
@ 2004-10-28  6:11       ` Denis Vlasenko
  2004-10-28 21:20         ` Lei Yang
  0 siblings, 1 reply; 14+ messages in thread
From: Denis Vlasenko @ 2004-10-28  6:11 UTC (permalink / raw)
  To: Lei Yang; +Cc: linux-kernel, kernelnewbies

On Thursday 28 October 2004 05:25, Lei Yang wrote:
> 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);

Can you stick to "reply below quote" style please?

> > If nobody could answer this question, what about another one? Is there 
> > a system call or a kernel interface that would allow me to write a 

Can you use read, write and seek system calls?
--
vda


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28  1:44   ` Lei Yang
  2004-10-28  2:25     ` Lei Yang
@ 2004-10-28  6:09     ` Denis Vlasenko
  2004-10-28 16:35     ` Shesha B.  Sreenivasamurthy
  2 siblings, 0 replies; 14+ messages in thread
From: Denis Vlasenko @ 2004-10-28  6:09 UTC (permalink / raw)
  To: Lei Yang, linux-kernel, kernelnewbies; +Cc: Lei Yang

> >> I am learning block device drivers and have a newbie question. Given 
> >> a block device, is there anyway that I could set its block size? For 
> >> example, I want to write a block device driver that will work on an 
> >> existing block device.  In this driver, I want block size smaller. 
> >> (The idea looks confusing but I could explain if anybody is 
> >> interested :- )  However,  typically the block size is 1KB, now I 
> >> want to set it to 512 or 256.  Can I do it?

256 - no way if hardware can do only 512-byte writes.

You need read-modify-write for this.
--
vda


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: set blksize of block device
@ 2004-10-28  6:07 gopu.bhaskar
  0 siblings, 0 replies; 14+ messages in thread
From: gopu.bhaskar @ 2004-10-28  6:07 UTC (permalink / raw)
  To: lya755, bijoyjth; +Cc: linux-kernel, kernelnewbies

> >
> Isn't there a bwrite similar to bread?
> 

http://mail.nl.linux.org/kernelnewbies/2003-06/msg00231.html

-Gopu.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-28  1:44   ` Lei Yang
@ 2004-10-28  2:25     ` Lei Yang
  2004-10-28  6:11       ` Denis Vlasenko
  2004-10-28  6:09     ` Denis Vlasenko
  2004-10-28 16:35     ` Shesha B.  Sreenivasamurthy
  2 siblings, 1 reply; 14+ messages in thread
From: Lei Yang @ 2004-10-28  2:25 UTC (permalink / raw)
  To: Lei Yang; +Cc: linux-kernel, kernelnewbies

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


Lei Yang wrote:

> If nobody could answer this question, what about another one? Is there 
> a system call or a kernel interface that would allow me to write a 
> block of data to block 1 of a certain block device?
>
> Thanks for your reply in advance!
>
> Lei
>
> Lei Yang wrote:
>
>> Please cc me if you have answers to this, I am not on the list. 
>> Thanks a lot!
>>
>> Lei Yang wrote:
>>
>>> Hello,
>>>
>>> I am learning block device drivers and have a newbie question. Given 
>>> a block device, is there anyway that I could set its block size? For 
>>> example, I want to write a block device driver that will work on an 
>>> existing block device.  In this driver, I want block size smaller. 
>>> (The idea looks confusing but I could explain if anybody is 
>>> interested :- )  However,  typically the block size is 1KB, now I 
>>> want to set it to 512 or 256.  Can I do it?
>>>
>>> TIA
>>> Lei
>>>
>>
>>
>>
>
>
>
> -- 
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
>
>



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-27 18:30 ` Lei Yang
@ 2004-10-28  1:44   ` Lei Yang
  2004-10-28  2:25     ` Lei Yang
                       ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Lei Yang @ 2004-10-28  1:44 UTC (permalink / raw)
  To: linux-kernel, kernelnewbies; +Cc: Lei Yang

If nobody could answer this question, what about another one? Is there a 
system call or a kernel interface that would allow me to write a block 
of data to block 1 of a certain block device?

Thanks for your reply in advance!

Lei

Lei Yang wrote:

> Please cc me if you have answers to this, I am not on the list. Thanks 
> a lot!
>
> Lei Yang wrote:
>
>> Hello,
>>
>> I am learning block device drivers and have a newbie question. Given 
>> a block device, is there anyway that I could set its block size? For 
>> example, I want to write a block device driver that will work on an 
>> existing block device.  In this driver, I want block size smaller. 
>> (The idea looks confusing but I could explain if anybody is 
>> interested :- )  However,  typically the block size is 1KB, now I 
>> want to set it to 512 or 256.  Can I do it?
>>
>> TIA
>> Lei
>>
>
>
>



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: set blksize of block device
  2004-10-27 18:19 Lei Yang
@ 2004-10-27 18:30 ` Lei Yang
  2004-10-28  1:44   ` Lei Yang
  0 siblings, 1 reply; 14+ messages in thread
From: Lei Yang @ 2004-10-27 18:30 UTC (permalink / raw)
  To: Lei Yang, linux-kernel

Please cc me if you have answers to this, I am not on the list. Thanks a 
lot!

Lei Yang wrote:

> Hello,
>
> I am learning block device drivers and have a newbie question. Given a 
> block device, is there anyway that I could set its block size? For 
> example, I want to write a block device driver that will work on an 
> existing block device.  In this driver, I want block size smaller. 
> (The idea looks confusing but I could explain if anybody is interested 
> :- )  However,  typically the block size is 1KB, now I want to set it 
> to 512 or 256.  Can I do it?
>
> TIA
> Lei
>



^ permalink raw reply	[flat|nested] 14+ messages in thread

* set blksize of block device
@ 2004-10-27 18:19 Lei Yang
  2004-10-27 18:30 ` Lei Yang
  0 siblings, 1 reply; 14+ messages in thread
From: Lei Yang @ 2004-10-27 18:19 UTC (permalink / raw)
  To: linux-kernel

Hello,

I am learning block device drivers and have a newbie question. Given a 
block device, is there anyway that I could set its block size? For 
example, I want to write a block device driver that will work on an 
existing block device.  In this driver, I want block size smaller. (The 
idea looks confusing but I could explain if anybody is interested :- )  
However,  typically the block size is 1KB, now I want to set it to 512 
or 256.  Can I do it?

TIA
Lei


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2004-11-01 13:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-28  3:34 set blksize of block device Bijoy Thomas
2004-10-28  3:42 ` Lei Yang
2004-11-01 13:55 ` Jon Masters
  -- strict thread matches above, loose matches on Subject: below --
2004-10-28  6:07 gopu.bhaskar
2004-10-27 18:19 Lei Yang
2004-10-27 18:30 ` Lei Yang
2004-10-28  1:44   ` Lei Yang
2004-10-28  2:25     ` Lei Yang
2004-10-28  6:11       ` Denis Vlasenko
2004-10-28 21:20         ` Lei Yang
2004-10-28 21:50           ` Todd Poynor
2004-10-28  6:09     ` Denis Vlasenko
2004-10-28 16:35     ` Shesha B.  Sreenivasamurthy
2004-10-28 21:04       ` Lei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).