grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Support for unknown size and not seekable files


From: Vladimir 'φ-coder/phcoder' Serbinenko
Subject: Re: [PATCH] Support for unknown size and not seekable files
Date: Sat, 15 Jan 2011 14:02:14 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20101226 Icedove/3.0.11

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: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]