linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: "Andries E. Brouwer" <Andries.Brouwer@cwi.nl>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/2] partitions: use sector size for EFI GPT
Date: Mon, 9 Nov 2009 22:33:38 +0100	[thread overview]
Message-ID: <20091109213338.GP5610@nb.net.home> (raw)
In-Reply-To: <20091109195832.GA25240@ub>

On Mon, Nov 09, 2009 at 08:58:32PM +0100, Andries E. Brouwer wrote:
> static size_t
> read_lba(struct block_device *bdev, u64 lba, u8 * buffer, size_t count)
> {
>         size_t totalreadcount = 0;
> 	sector_t n = lba * (bdev_logical_block_size(bdev) / 512);
> 
>         if (!bdev || !buffer || lba > last_lba(bdev))
>                 return 0;
> 
>         while (count) {
>                 int copied = 512;
>                 Sector sect;
>                 unsigned char *data = read_dev_sector(bdev, n++, &sect);
>                 if (!data)
>                         break;
>                 if (copied > count)
>                         copied = count;
>                 memcpy(buffer, data, copied);
>                 put_dev_sector(sect);
>                 buffer += copied;
>                 totalreadcount +=copied;
>                 count -= copied;
>         }
>         return totalreadcount;
> }
> 
> Ugly - it looks as if you call read_dev_sector 8 times and each time

 Yes, the function is really not elegant, but it follows the way how
 all fs/partitions code reads sectors from disks.

> do a put_dev_sector afterwards to forget it again. Doesnt that mean
> that in order to read a 4096-byte sector the kernel goes to the hardware
> 8 times?

 read_dev_sector() works with 512-byte sectors and it's interface to
 read_mapping_page() which works with pages from cache.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>

      reply	other threads:[~2009-11-09 21:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-23 10:36 [PATCH 1/2] partitions: use sector size for EFI GPT Karel Zak
2009-10-23 10:36 ` [PATCH 2/2] partitions: read whole sector with EFI GPT header Karel Zak
2009-11-09 13:08 ` [PATCH 1/2] partitions: use sector size for EFI GPT Karel Zak
2009-11-09 19:50   ` Jens Axboe
2009-11-09 19:58   ` Andries E. Brouwer
2009-11-09 21:33     ` Karel Zak [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091109213338.GP5610@nb.net.home \
    --to=kzak@redhat.com \
    --cc=Andries.Brouwer@cwi.nl \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).