From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: grub-devel@gnu.org
Subject: Re: [PATCH] Support for unknown size and not seekable files
Date: Sat, 15 Jan 2011 14:02:14 +0100 [thread overview]
Message-ID: <4D319AD6.9080909@gmail.com> (raw)
In-Reply-To: <201101151315.43836.szymon@janc.net.pl>
[-- Attachment #1: Type: text/plain, Size: 1647 bytes --]
On 01/15/2011 01:15 PM, Szymon Janc wrote:
> On Saturday 15 January 2011 01:37:13 Seth Goldberg wrote:
>
>> Hi,
>>
>> Thanks for this. What's the goal of this patch? It seems that it marks
>> the size and unknown until it gets to the metadata that indicates the
>> file's size, then updates the size to the correct size, right? Where do
>> you see this being useful?
>>
> The biggest problem now is that opening compressed files require seeking to the
> end to get uncompressed size so on not seekable fs this causes
> grub_file_open("foo") to read whole file. With this patchset this is no longer a
> case. So in that use case
>
> file = grub_file_open ("foo");
> while (grub_file_read (file, buf, sizeof (buf)) > 0) { ... }
>
> foo is read only once.
>
>
>
>> It would seems that even with this patch, one
>> would still need to read a gzipped file twice to be able to get its size,
>> then allocate a contiguous buffer large enough to hold the entire thing
>> (if that is desired (which, in some cases, it is :))).
>>
> Wouldn't sth like that work?
>
>
It's O(N^2).
You need to always at least double the allocation every time you exceed
already allocated buffer in order to get O(N)
> char * ptr = 0;
> char buf[0x10000];
> unsigned size, size_total = 0;
>
> grub_file_t file = grub_file_open ("foo");
> while ( (size = grub_file_read (file, buf, sizeof (buf))) > 0)
> {
> ptr = grub_realloc (ptr, size_total + size);
> grub_memcpy (ptr+size_total, buf, size);
> size_total += size;
> }
>
>
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]
prev parent reply other threads:[~2011-01-15 13:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-15 0:21 [PATCH] Support for unknown size and not seekable files Szymon Janc
2011-01-15 0:37 ` Seth Goldberg
2011-01-15 12:15 ` Szymon Janc
2011-01-15 13:02 ` Vladimir 'φ-coder/phcoder' Serbinenko [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=4D319AD6.9080909@gmail.com \
--to=phcoder@gmail.com \
--cc=grub-devel@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.