From: Gustavo Sverzut Barbieri Date: Sat, 10 Dec 2011 13:53:51 +0000 (-0200) Subject: index: cleanup header, move as much as possible to libkmod-index.c X-Git-Tag: v1~55^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=148226ed92077527ccfc9f38eff6e7771714449e;p=thirdparty%2Fkmod.git index: cleanup header, move as much as possible to libkmod-index.c --- diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index d97a03c7..40b223cf 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -32,6 +32,45 @@ /* index.c: module index file shared functions for modprobe and depmod */ +#define INDEX_CHILDMAX 128 + +/* Disk format: + + uint32_t magic = INDEX_MAGIC; + uint32_t version = INDEX_VERSION; + uint32_t root_offset; + + (node_offset & INDEX_NODE_MASK) specifies the file offset of nodes: + + char[] prefix; // nul terminated + + char first; + char last; + uint32_t children[last - first + 1]; + + uint32_t value_count; + struct { + uint32_t priority; + char[] value; // nul terminated + } values[value_count]; + + (node_offset & INDEX_NODE_FLAGS) indicates which fields are present. + Empty prefixes are omitted, leaf nodes omit the three child-related fields. + + This could be optimised further by adding a sparse child format + (indicated using a new flag). + */ + +/* Format of node offsets within index file */ +enum node_offset { + INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ + INDEX_NODE_PREFIX = 0x80000000, + INDEX_NODE_VALUES = 0x40000000, + INDEX_NODE_CHILDS = 0x20000000, + + INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ +}; + void index_values_free(struct index_value *values) { while (values) { diff --git a/libkmod/libkmod-index.h b/libkmod/libkmod-index.h index a6aba5e8..b8c1fb9d 100644 --- a/libkmod/libkmod-index.h +++ b/libkmod/libkmod-index.h @@ -110,53 +110,6 @@ struct index_value { }; /* In-memory index (depmod only) */ - -#define INDEX_CHILDMAX 128 -struct index_node { - char *prefix; /* path compression */ - struct index_value *values; - unsigned char first; /* range of child nodes */ - unsigned char last; - struct index_node *children[INDEX_CHILDMAX]; /* indexed by character */ -}; - -/* Disk format: - - uint32_t magic = INDEX_MAGIC; - uint32_t version = INDEX_VERSION; - uint32_t root_offset; - - (node_offset & INDEX_NODE_MASK) specifies the file offset of nodes: - - char[] prefix; // nul terminated - - char first; - char last; - uint32_t children[last - first + 1]; - - uint32_t value_count; - struct { - uint32_t priority; - char[] value; // nul terminated - } values[value_count]; - - (node_offset & INDEX_NODE_FLAGS) indicates which fields are present. - Empty prefixes are omitted, leaf nodes omit the three child-related fields. - - This could be optimised further by adding a sparse child format - (indicated using a new flag). - */ - -/* Format of node offsets within index file */ -enum node_offset { - INDEX_NODE_FLAGS = 0xF0000000, /* Flags in high nibble */ - INDEX_NODE_PREFIX = 0x80000000, - INDEX_NODE_VALUES = 0x40000000, - INDEX_NODE_CHILDS = 0x20000000, - - INDEX_NODE_MASK = 0x0FFFFFFF, /* Offset value */ -}; - struct index_file; struct index_file *index_file_open(const char *filename); void index_file_close(struct index_file *idx);