1 /* hivex internal header
2 * Copyright (C) 2009-2011 Red Hat Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation;
7 * version 2.1 of the License only.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef HIVEX_INTERNAL_H_
20 #define HIVEX_INTERNAL_H_
31 /* Registry file, memory mapped if read-only, or malloc'd if writing. */
34 struct ntreg_header *hdr;
37 /* Use a bitmap to store which file offsets are valid (point to a
38 * used block). We only need to store 1 bit per 32 bits of the file
39 * (because blocks are 4-byte aligned). We found that the average
40 * block size in a registry file is ~50 bytes. So roughly 1 in 12
41 * bits in the bitmap will be set, making it likely a more efficient
42 * structure than a hash table.
45 #define BITMAP_SET(bitmap,off) (bitmap[(off)>>5] |= 1 << (((off)>>2)&7))
46 #define BITMAP_CLR(bitmap,off) (bitmap[(off)>>5] &= ~ (1 << (((off)>>2)&7)))
47 #define BITMAP_TST(bitmap,off) (bitmap[(off)>>5] & (1 << (((off)>>2)&7)))
48 #define IS_VALID_BLOCK(h,off) \
49 (((off) & 3) == 0 && \
51 (off) < (h)->size && \
52 BITMAP_TST((h)->bitmap,(off)))
54 /* Fields from the header, extracted from little-endianness hell. */
55 size_t rootoffs; /* Root key offset (always an nk-block). */
56 size_t endpages; /* Offset of end of pages. */
57 int64_t last_modified; /* mtime of base block. */
60 size_t endblocks; /* Offset to next block allocation (0
61 if not allocated anything yet). */
64 /* Internal data for mmap replacement */
69 #define STREQ(a,b) (strcmp((a),(b)) == 0)
70 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
71 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
72 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
73 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
74 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
75 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
76 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
77 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
79 #endif /* HIVEX_INTERNAL_H_ */