From mboxrd@z Thu Jan 1 00:00:00 1970 From: shampavman.cg@gmail.com (shampavman) Date: Tue, 14 May 2013 12:05:32 +0530 Subject: how do i read a block In-Reply-To: References: <51909EE2.30605@gmail.com> Message-ID: <5191DB34.2010206@gmail.com> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On 05/14/2013 11:59 AM, Prashant Shah wrote: > Hi, > > On Mon, May 13, 2013 at 9:52 PM, Matthias Brugger > wrote: >> El 13/05/2013 10:07, "shampavman" 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.