1 #ifndef _WIMLIB_LOOKUP_TABLE_H
2 #define _WIMLIB_LOOKUP_TABLE_H
3 #include "wimlib_internal.h"
7 /* Size of each lookup table entry in the WIM file. */
8 #define WIM_LOOKUP_TABLE_ENTRY_DISK_SIZE 50
10 #define LOOKUP_FLAG_ADS_OK 0x00000001
11 #define LOOKUP_FLAG_DIRECTORY_OK 0x00000002
12 #define LOOKUP_FLAG_FOLLOW_SYMLINKS 0x00000004
15 /* A lookup table that is used to translate the hash codes of dentries into the
16 * offsets and sizes of uncompressed or compressed file resources. It is
17 * implemented as a hash table. */
19 struct lookup_table_entry **array;
27 /* An entry in the lookup table in the WIM file. */
28 struct lookup_table_entry {
30 /* The next struct lookup_table_entry in the hash bucket. NULL if this is the
32 struct lookup_table_entry *next;
34 /* @resource_entry is read from the lookup table in the WIM
35 * file; it says where to find the file resource in the WIM
36 * file, and whether it is compressed or not. */
37 struct resource_entry resource_entry;
39 /* Currently ignored; set to 1 in new lookup table entries. */
42 /* If %true, this lookup table entry corresponds to a symbolic link
43 * reparse buffer. @symlink_reparse_data_buf will give the target of
44 * the symbolic link. */
47 /* Number of times this lookup table entry is referenced by dentries. */
51 /* SHA1 hash of the file resource pointed to by this lookup
53 u8 hash[WIM_HASH_SIZE];
55 /* First 4 or 8 bytes of the SHA1 hash, used for inserting the
56 * entry into the hash table. Since the SHA1 hashes can be
57 * considered random, we don't really need the full 20 byte hash
58 * just to insert the entry in a hash table. */
62 /* If @file_on_disk != NULL, the file resource indicated by this lookup
63 * table entry is not in the WIM file, but rather a file on disk; this
64 * occurs for files that are added to the WIM. In that case,
65 * file_on_disk is the name of the file in the outside filesystem.
66 * It will not be compressed, and its size will be given by
67 * resource_entry.size and resource_entry.original_size. */
70 char *staging_file_name;
72 struct lookup_table_entry *next_lte_in_swm;
76 struct { /* Used for wimlib_export. */
78 /* If (other_wim_fp != NULL), the file resource indicated
79 * by this lookup table entry is in a different WIM
80 * file, and other_wim_fp is the FILE* for it. */
83 /* Compression type used in other WIM. */
87 struct wimlib_fd **fds;
88 u16 num_allocated_fds;
93 /* When a WIM file is written, out_refcnt starts at 0 and is incremented
94 * whenever the file resource pointed to by this lookup table entry
95 * needs to be written. Naturally, the file resource only need to be
96 * written when out_refcnt is 0. Incrementing it further is needed to
97 * find the correct reference count to write to the lookup table in the
98 * output file, which may be less than the regular refcnt if not all
99 * images in the WIM file are written.
101 * output_resource_entry is the struct resource_entry for the position of the
102 * file resource when written to the output file. */
104 struct resource_entry output_resource_entry;
105 struct list_head lte_group_list;
106 struct list_head staging_list;
109 extern struct lookup_table *new_lookup_table(size_t capacity);
111 extern void lookup_table_insert(struct lookup_table *table,
112 struct lookup_table_entry *lte);
114 extern void lookup_table_unlink(struct lookup_table *table,
115 struct lookup_table_entry *lte);
117 extern struct lookup_table_entry *
118 lookup_table_decrement_refcnt(struct lookup_table* table, const u8 hash[]);
120 extern struct lookup_table_entry *
121 lte_decrement_refcnt(struct lookup_table_entry *lte,
122 struct lookup_table *table);
125 extern struct lookup_table_entry *new_lookup_table_entry();
127 extern int for_lookup_table_entry(struct lookup_table *table,
128 int (*visitor)(struct lookup_table_entry *, void *),
131 extern struct lookup_table_entry *
132 __lookup_resource(const struct lookup_table *lookup_table, const u8 hash[]);
134 extern int lookup_resource(WIMStruct *w, const char *path,
135 int lookup_flags, struct dentry **dentry_ret,
136 struct lookup_table_entry **lte_ret,
137 unsigned *stream_idx_ret);
139 extern int zero_out_refcnts(struct lookup_table_entry *entry, void *ignore);
141 extern int print_lookup_table_entry(struct lookup_table_entry *entry, void *ignore);
143 extern int read_lookup_table(FILE *fp, u64 offset, u64 size,
144 struct lookup_table **table_ret);
146 extern void free_lookup_table(struct lookup_table *table);
148 extern int write_lookup_table_entry(struct lookup_table_entry *lte, void *__out);
150 extern void free_lookup_table_entry(struct lookup_table_entry *lte);
152 extern void resolve_lookup_table_entries(struct dentry *root,
153 struct lookup_table *table);
155 /* Writes the lookup table to the output file. */
156 static inline int write_lookup_table(struct lookup_table *table, FILE *out)
158 return for_lookup_table_entry(table, write_lookup_table_entry, out);
161 /* Unlinks and frees an entry from a lookup table. */
162 static inline void lookup_table_remove(struct lookup_table *table,
163 struct lookup_table_entry *lte)
165 lookup_table_unlink(table, lte);
166 free_lookup_table_entry(lte);
169 static inline struct resource_entry* wim_metadata_resource_entry(WIMStruct *w)
171 return &w->image_metadata[
172 w->current_image - 1].metadata_lte->resource_entry;