[settings] Add the notion of a "tag magic" to numbered settings

Settings can be constructed using a dotted-decimal notation, to allow
for access to unnamed settings.  The default interpretation is as a
DHCP option number (with encapsulated options represented as
"<encapsulating option>.<encapsulated option>".

In several contexts (e.g. SMBIOS, Phantom CLP), it is useful to
interpret the dotted-decimal notation as referring to non-DHCP
options.  In this case, it becomes necessary for these contexts to
ignore standard DHCP options, otherwise we end up trying to, for
example, retrieve the boot filename from SMBIOS.

Allow settings blocks to specify a "tag magic".  When dotted-decimal
notation is used to construct a setting, the tag magic value of the
originating settings block will be ORed in to the tag number.
Store/fetch methods can then check for the magic number before
interpreting arbitrarily-numbered settings.
This commit is contained in:
Michael Brown
2008-10-29 18:17:02 +00:00
parent 621101c36a
commit 0a6c66a830
7 changed files with 60 additions and 25 deletions

View File

@@ -24,6 +24,16 @@
#include <gpxe/uuid.h>
#include <smbios.h>
/** SMBIOS settings tag magic number */
#define SMBIOS_TAG_MAGIC 0x5B /* "SmBios" */
/**
* Construct SMBIOS empty tag
*
* @ret tag SMBIOS setting tag
*/
#define SMBIOS_EMPTY_TAG ( SMBIOS_TAG_MAGIC << 24 )
/**
* Construct SMBIOS raw-data tag
*
@@ -33,7 +43,8 @@
* @ret tag SMBIOS setting tag
*/
#define SMBIOS_RAW_TAG( _type, _structure, _field ) \
( ( (_type) << 16 ) | \
( ( SMBIOS_TAG_MAGIC << 24 ) | \
( (_type) << 16 ) | \
( offsetof ( _structure, _field ) << 8 ) | \
( sizeof ( ( ( _structure * ) 0 )->_field ) ) )
@@ -46,7 +57,8 @@
* @ret tag SMBIOS setting tag
*/
#define SMBIOS_STRING_TAG( _type, _structure, _field ) \
( ( (_type) << 16 ) | \
( ( SMBIOS_TAG_MAGIC << 24 ) | \
( (_type) << 16 ) | \
( offsetof ( _structure, _field ) << 8 ) )
/**
@@ -78,16 +90,18 @@ static int smbios_fetch ( struct settings *settings __unused,
struct setting *setting,
void *data, size_t len ) {
struct smbios_structure structure;
unsigned int tag_magic;
unsigned int tag_type;
unsigned int tag_offset;
unsigned int tag_len;
int rc;
/* Split tag into type, offset and length */
tag_type = ( setting->tag >> 16 );
tag_magic = ( setting->tag >> 24 );
tag_type = ( ( setting->tag >> 16 ) & 0xff );
tag_offset = ( ( setting->tag >> 8 ) & 0xff );
tag_len = ( setting->tag & 0xff );
if ( ! tag_type )
if ( tag_magic != SMBIOS_TAG_MAGIC )
return -ENOENT;
/* Find SMBIOS structure */
@@ -127,6 +141,7 @@ static struct settings_operations smbios_settings_operations = {
static struct settings smbios_settings = {
.refcnt = NULL,
.name = "smbios",
.tag_magic = SMBIOS_EMPTY_TAG,
.siblings = LIST_HEAD_INIT ( smbios_settings.siblings ),
.children = LIST_HEAD_INIT ( smbios_settings.children ),
.op = &smbios_settings_operations,