2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
26 #define BLOB_PAGEBITS 15
27 #define BLOB_PAGESIZE (1 << BLOB_PAGEBITS)
29 typedef struct _Attrblobpage
31 /* mapped_at == -1 --> not loaded, otherwise offset into
32 store->blob_store. The size of the mapping is BLOB_PAGESIZE
33 except for the last page. */
34 unsigned int mapped_at;
36 /* file_size == 0 means the page is not backed by some file storage.
37 Otherwise it is L*2+(compressed ? 1 : 0), with L being the data
56 unsigned int blob_next_free;
58 unsigned int num_pages;
60 /* mapped[i] is zero if nothing is mapped at logical page I,
61 otherwise it contains the pagenumber plus one (of the mapped page). */
63 unsigned int nmapped, ncanmap;
64 unsigned int rr_counter;
73 unsigned ndirstack, dirstack_size;
76 /* A space efficient in memory representation. It's read-only. */
77 /* flat_attrs[ent2attr[i]] are the attrs for entity i. */
78 unsigned int *ent2attr;
79 unsigned char *flat_attrs;
80 unsigned int attr_next_free;
90 unsigned nschemata, szschemata;
92 unsigned int packed:1;
95 void add_attr_from_file (Attrstore *s, unsigned entry, Id name, int type, Id *idmap, unsigned maxid, FILE *fp);
96 void read_or_setup_pages (FILE *fp, Attrstore *s);
98 #define get_num(ptr,val) do { \
99 typedef int __wrong_buf__[(1-sizeof((ptr)[0])) * (sizeof((ptr)[0])-1)];\
102 unsigned char __c = *((ptr)++); \
103 (val) = ((val) << 7) | (__c & 0x7F); \
104 if ((__c & 0x80) == 0) \
110 unsigned char *attrs;
112 unsigned char *attrs_next;
116 /* The following fields could be a union, but if we do that GCC
117 doesn't scalarize these fields anymore, hence real memory accesses
118 would remain, so don't do that. */
121 unsigned int as_chunk[2];
122 const char *as_string;
123 const unsigned char *as_numlist;
127 ai_init (Attrstore *s, unsigned int i, attr_iterator *ai)
129 ai->attrs = s->flat_attrs + s->ent2attr[i];
130 unsigned int this_schema;
131 get_num (ai->attrs, this_schema);
132 ai->schema = s->schemata + s->schemaofs[this_schema];
134 /* Initialize all fields so we get no uninit warnings later.
135 Don't use memset() to initialize this structure, it would make
136 GCC not scalarize it. */
139 ai->as_chunk[0] = ai->as_chunk[1] = 0;
145 ai_step (Attrstore *s, attr_iterator *ai)
147 Id key = *(ai->schema);
150 ai->name = s->keys[key].name;
151 ai->type = s->keys[key].type;
152 ai->attrs_next = ai->attrs;
161 get_num (ai->attrs_next, val);
165 case TYPE_ATTR_CHUNK:
167 unsigned int val1, val2;
168 get_num (ai->attrs_next, val1);
169 ai->as_chunk[0] = val1;
170 get_num (ai->attrs_next, val2);
171 ai->as_chunk[1] = val2;
174 case TYPE_ATTR_STRING:
176 ai->as_string = (const char *) ai->attrs_next;
177 ai->attrs_next += strlen ((const char*)ai->attrs_next) + 1;
180 case TYPE_ATTR_INTLIST:
182 ai->as_numlist = ai->attrs_next;
186 get_num (ai->attrs_next, val);
192 case TYPE_ATTR_LOCALIDS:
194 ai->as_numlist = ai->attrs_next;
198 get_num (ai->attrs_next, val);
205 /* ??? Convert TYPE_ATTR_SPECIAL_* to _INT type with the right value? */
211 #define FOR_ATTRS(s,i,ai) \
212 for (ai_init (s, i, ai); ai_step (s, ai); (ai)->schema++,(ai)->attrs = (ai)->attrs_next)