[Cbe-oss-dev] [patch 16/18] petitboot: Add system helper routines

Geoff Levand geoffrey.levand at am.sony.com
Mon Apr 13 08:14:48 EST 2009


On 03/30/2009 03:37 AM, Jeremy Kerr wrote:
>> +	static const char s_file[] = "file://";
>> +	static const char s_ftp[] = "ftp://";
>> +	static const char s_http[] = "http://";
>> +	static const char s_https[] = "https://";
>> +	static const char s_nfs[] = "nfs://";
>> +	static const char s_scp[] = "scp://";
>> +	static const char s_tftp[] = "tftp://";
> 
> [snip]
> 
>> +
>> +	if (!strncasecmp(s_url, s_file, sizeof(s_file) - 1)) {
>> +		url->scheme = pb_url_file;
>> +		p = s_url + sizeof(s_file) - 1;
>> +		goto got_scheme;
>> +	}
>> +
>> +	if (!strncasecmp(s_url, s_ftp, sizeof(s_ftp) - 1)) {
>> +		url->scheme = pb_url_ftp;
>> +		p = s_url + sizeof(s_ftp) - 1;
>> +		goto got_scheme;
>> +	}
> 
> 
> static const struct {
> 	const char *scheme_str;
> 	enum pb_url_scheme scheme;
> } schemes[] = {
> 	{ "tftp", pb_url_tftp },
> 	{ "file", pb_url_file },
>     .... 
> }
> 
> for (i = 0; i < ARRAY_SIZE(schemes); i++) {
> 	int len = strlen(schemes[i].scheme_str);
> 
> 	if (strncasecmp(s_url, schemes[i].scheme_str, len)
> 		continue;
> 
> 	url->scheme = schemes[i].scheme
> 	p = s_url + len;
> }

I had the same idea, but didn't get to it before posting.
It is now done.

> We could even hook the load_*() functions into that schemes[] array, 
> which would simplify pb_load_file()...

I decided against this, I thought it better to have the loader
know nothing about url parsing.  It also allows some extra logic
in pb_load_file(), based on the url type.

> (or maybe do this in a separate common/url.c object? up to you.)

OK, I set that up.  I also made a common/loader.c.

There were some user requests to load bootloader config files
from a server so the config files could be centrally maintained
in a big installation.  If we decide to support something like
that we can move loader.c and url.c to lib/ and use them in the
daemon.

-Geoff





More information about the cbe-oss-dev mailing list