* how do i read a block
@ 2013-05-13 8:05 shampavman
2013-05-13 14:32 ` Valdis.Kletnieks at vt.edu
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: shampavman @ 2013-05-13 8:05 UTC (permalink / raw)
To: kernelnewbies
Hi all,
Supposing i create a file of size 10K, it will occupy 2 blocks (4K each).
Now if i want to read only 1 block from it how can i do it?
read(fd, buf, 4096) ;
would this mean i would read the first block and all its contents?
Thanks
^ permalink raw reply [flat|nested] 9+ messages in thread
* how do i read a block
2013-05-13 8:05 how do i read a block shampavman
@ 2013-05-13 14:32 ` Valdis.Kletnieks at vt.edu
2013-05-13 16:22 ` Matthias Brugger
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2013-05-13 14:32 UTC (permalink / raw)
To: kernelnewbies
On Mon, 13 May 2013 13:35:54 +0530, shampavman said:
> Hi all,
>
> Supposing i create a file of size 10K, it will occupy 2 blocks (4K each).
> Now if i want to read only 1 block from it how can i do it?
>
> read(fd, buf, 4096) ;
> would this mean i would read the first block and all its contents?
This isn't a kernel question, it's a C 101 question.
But yes, if you only want to read the first 4K, you just read the first 4K.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130513/49a9d745/attachment.bin
^ permalink raw reply [flat|nested] 9+ messages in thread
* how do i read a block
2013-05-13 8:05 how do i read a block shampavman
2013-05-13 14:32 ` Valdis.Kletnieks at vt.edu
@ 2013-05-13 16:22 ` Matthias Brugger
2013-05-14 6:29 ` Prashant Shah
2013-05-14 20:26 ` Manish Katiyar
2013-05-15 9:10 ` Sankar P
3 siblings, 1 reply; 9+ messages in thread
From: Matthias Brugger @ 2013-05-13 16:22 UTC (permalink / raw)
To: kernelnewbies
El 13/05/2013 10:07, "shampavman" <shampavman.cg@gmail.com> va escriure:
>
> Hi all,
>
> Supposing i create a file of size 10K, it will occupy 2 blocks (4K each).
> Now if i want to read only 1 block from it how can i do it?
>
> read(fd, buf, 4096) ;
> would this mean i would read the first block and all its contents?
You actually might even read more, depending on your file system. The
dentrys and inodes are stored in blocks on the disk as well. You can try to
access your disk through /dev/sdX directly, but beware that when writing
you will most probably destroy your data on that disk.
Regards,
Matthias
>
> Thanks
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130513/2c2251a1/attachment.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* how do i read a block
2013-05-13 16:22 ` Matthias Brugger
@ 2013-05-14 6:29 ` Prashant Shah
2013-05-14 6:35 ` shampavman
0 siblings, 1 reply; 9+ messages in thread
From: Prashant Shah @ 2013-05-14 6:29 UTC (permalink / raw)
To: kernelnewbies
Hi,
On Mon, May 13, 2013 at 9:52 PM, Matthias Brugger
<matthias.bgg@gmail.com> wrote:
>
> El 13/05/2013 10:07, "shampavman" <shampavman.cg@gmail.com> va escriure:
>
>
>>
>> Hi all,
>>
>> Supposing i create a file of size 10K, it will occupy 2 blocks (4K each).
>> Now if i want to read only 1 block from it how can i do it?
>>
>> read(fd, buf, 4096) ;
>> would this mean i would read the first block and all its contents?
>
One way to do this is use the FIBMAP ioctl to the get the block
numbers of a file and then seek the disk /dev/sdX directly and use the
read() to get data block.
Regards.
^ permalink raw reply [flat|nested] 9+ messages in thread
* how do i read a block
2013-05-14 6:29 ` Prashant Shah
@ 2013-05-14 6:35 ` shampavman
2013-05-14 20:17 ` Valdis.Kletnieks at vt.edu
0 siblings, 1 reply; 9+ messages in thread
From: shampavman @ 2013-05-14 6:35 UTC (permalink / raw)
To: kernelnewbies
On 05/14/2013 11:59 AM, Prashant Shah wrote:
> Hi,
>
> On Mon, May 13, 2013 at 9:52 PM, Matthias Brugger
> <matthias.bgg@gmail.com> wrote:
>> El 13/05/2013 10:07, "shampavman" <shampavman.cg@gmail.com> va escriure:
>>
>>
>>> Hi all,
>>>
>>> Supposing i create a file of size 10K, it will occupy 2 blocks (4K each).
>>> Now if i want to read only 1 block from it how can i do it?
>>>
>>> read(fd, buf, 4096) ;
>>> would this mean i would read the first block and all its contents?
> One way to do this is use the FIBMAP ioctl to the get the block
> numbers of a file and then seek the disk /dev/sdX directly and use the
> read() to get data block.
But why does a simple read not turn out 1 block for me?
Eg, i know my block size if 4k and my file (according to du) reports
that it's using 8k of space.
So when i read the file via the read() and ask it to give me the 'first
4k' bytes, would that not return 1 block ?
thanks
>
> Regards.
^ permalink raw reply [flat|nested] 9+ messages in thread
* how do i read a block
2013-05-14 6:35 ` shampavman
@ 2013-05-14 20:17 ` Valdis.Kletnieks at vt.edu
0 siblings, 0 replies; 9+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2013-05-14 20:17 UTC (permalink / raw)
To: kernelnewbies
On Tue, 14 May 2013 12:05:32 +0530, shampavman said:
> But why does a simple read not turn out 1 block for me?
So explain to us why you think a read of 4096 bytes is reading something
other than 1 4K block?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130514/3a107ee9/attachment.bin
^ permalink raw reply [flat|nested] 9+ messages in thread
* how do i read a block
2013-05-13 8:05 how do i read a block shampavman
2013-05-13 14:32 ` Valdis.Kletnieks at vt.edu
2013-05-13 16:22 ` Matthias Brugger
@ 2013-05-14 20:26 ` Manish Katiyar
2013-05-15 9:10 ` Sankar P
3 siblings, 0 replies; 9+ messages in thread
From: Manish Katiyar @ 2013-05-14 20:26 UTC (permalink / raw)
To: kernelnewbies
On Mon, May 13, 2013 at 1:05 AM, shampavman <shampavman.cg@gmail.com> wrote:
> Hi all,
>
> Supposing i create a file of size 10K, it will occupy 2 blocks (4K each).
>
I must be missing something obvious. Why does a file of 10K only needs 2
blocks of 4K ? You haven't mentioned that it has any holes in it.
> Now if i want to read only 1 block from it how can i do it?
>
> read(fd, buf, 4096) ;
> would this mean i would read the first block and all its contents?
>
> Thanks
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
--
Thanks -
Manish
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130514/19439946/attachment.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* how do i read a block
2013-05-13 8:05 how do i read a block shampavman
` (2 preceding siblings ...)
2013-05-14 20:26 ` Manish Katiyar
@ 2013-05-15 9:10 ` Sankar P
3 siblings, 0 replies; 9+ messages in thread
From: Sankar P @ 2013-05-15 9:10 UTC (permalink / raw)
To: kernelnewbies
On Mon, May 13, 2013 at 1:35 PM, shampavman <shampavman.cg@gmail.com> wrote:
> Hi all,
>
> Supposing i create a file of size 10K, it will occupy 2 blocks (4K each).
> Now if i want to read only 1 block from it how can i do it?
>
It will require 3 blocks.
> read(fd, buf, 4096) ;
> would this mean i would read the first block and all its contents?
>
It may be read even further (readahead)
If you are in kernel mode, and if you want to implement your own
filesystem and want to read a single block, you can use the sb_bread
function.
--
Sankar P
http://psankar.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* how do i read a block
@ 2013-05-15 13:43 Shampavman
0 siblings, 0 replies; 9+ messages in thread
From: Shampavman @ 2013-05-15 13:43 UTC (permalink / raw)
To: kernelnewbies
Sorry imeant 3blocks
Sankar P <sankar.curiosity@gmail.com> wrote:
>On Mon, May 13, 2013 at 1:35 PM, shampavman <shampavman.cg@gmail.com> wrote:
>> Hi all,
>>
>> Supposing i create a file of size 10K, it will occupy 2 blocks (4K each).
>> Now if i want to read only 1 block from it how can i do it?
>>
>
>It will require 3 blocks.
>
>
>> read(fd, buf, 4096) ;
>> would this mean i would read the first block and all its contents?
>>
>
>It may be read even further (readahead)
>
>If you are in kernel mode, and if you want to implement your own
>filesystem and want to read a single block, you can use the sb_bread
>function.
>
>
>--
>Sankar P
>http://psankar.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-05-15 13:43 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-13 8:05 how do i read a block shampavman
2013-05-13 14:32 ` Valdis.Kletnieks at vt.edu
2013-05-13 16:22 ` Matthias Brugger
2013-05-14 6:29 ` Prashant Shah
2013-05-14 6:35 ` shampavman
2013-05-14 20:17 ` Valdis.Kletnieks at vt.edu
2013-05-14 20:26 ` Manish Katiyar
2013-05-15 9:10 ` Sankar P
-- strict thread matches above, loose matches on Subject: below --
2013-05-15 13:43 Shampavman
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).