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
11 /* A lookup table that is used to translate the hash codes of dentries into the
12 * offsets and sizes of uncompressed or compressed file resources. It is
13 * implemented as a hash table. */
15 struct lookup_table_entry **array;
20 /* An entry in the lookup table in the WIM file. */
21 struct lookup_table_entry {
23 /* The next struct lookup_table_entry in the hash bucket. NULL if this is the
25 struct lookup_table_entry *next;
27 /* @resource_entry is read from the lookup table in the WIM
28 * file; it says where to find the file resource in the WIM
29 * file, and whether it is compressed or not. */
30 struct resource_entry resource_entry;
32 /* Currently ignored; set to 1 in new lookup table entries. */
35 /* Number of times this lookup table entry is referenced by dentries. */
38 /* SHA1 hash of the file resource pointed to by this lookup table entry */
39 u8 hash[WIM_HASH_SIZE];
41 /* If @file_on_disk != NULL, the file resource indicated by this lookup
42 * table entry is not in the WIM file, but rather a file on disk; this
43 * occurs for files that are added to the WIM. In that case,
44 * file_on_disk is the name of the file in the outside filesystem.
45 * It will not be compressed, and its size will be given by
46 * resource_entry.size and resource_entry.original_size. */
49 char *staging_file_name;
50 struct lookup_table_entry *next_lte_in_swm;
54 struct { /* Used for wimlib_export. */
56 /* If (other_wim_fp != NULL), the file resource indicated
57 * by this lookup table entry is in a different WIM
58 * file, and other_wim_fp is the FILE* for it. */
61 /* Compression type used in other WIM. */
65 struct { /* Used for read-write mounts. */
68 /* Offset of the stream file_on_disk_fd. */
72 /* If file_on_disk_fd, if it is not -1, is the file
73 * descriptor, opened for reading, for file_on_disk. */
76 /* Number of times the file has been opened.
77 * file_on_disk_fd can be closed when num_times_opened
78 * is decremented to 0. */
79 int staging_num_times_opened;
83 /* When a WIM file is written, out_refcnt starts at 0 and is incremented
84 * whenever the file resource pointed to by this lookup table entry
85 * needs to be written. Naturally, the file resource only need to be
86 * written when out_refcnt is 0. Incrementing it further is needed to
87 * find the correct reference count to write to the lookup table in the
88 * output file, which may be less than the regular refcnt if not all
89 * images in the WIM file are written.
91 * output_resource_entry is the struct resource_entry for the position of the
92 * file resource when written to the output file. */
94 struct resource_entry output_resource_entry;
97 extern struct lookup_table *new_lookup_table(size_t capacity);
99 extern void lookup_table_insert(struct lookup_table *table,
100 struct lookup_table_entry *lte);
102 extern void lookup_table_unlink(struct lookup_table *table,
103 struct lookup_table_entry *lte);
105 extern void lookup_table_decrement_refcnt(struct lookup_table* table,
109 extern struct lookup_table_entry *new_lookup_table_entry();
111 extern int for_lookup_table_entry(struct lookup_table *table,
112 int (*visitor)(struct lookup_table_entry *, void *),
115 extern struct lookup_table_entry *lookup_resource(const struct lookup_table *table,
118 static inline struct lookup_table_entry *
119 wim_lookup_resource(const WIMStruct *w, const struct dentry *dentry)
121 return lookup_resource(w->lookup_table, dentry->hash);
124 extern int zero_out_refcnts(struct lookup_table_entry *entry, void *ignore);
126 extern int print_lookup_table_entry(struct lookup_table_entry *entry, void *ignore);
128 extern int read_lookup_table(FILE *fp, u64 offset, u64 size,
129 struct lookup_table **table_ret);
131 extern void free_lookup_table(struct lookup_table *table);
133 extern int write_lookup_table_entry(struct lookup_table_entry *lte, void *__out);
135 static inline void free_lookup_table_entry(struct lookup_table_entry *lte)
138 FREE(lte->file_on_disk);
143 /* Writes the lookup table to the output file. */
144 static inline int write_lookup_table(struct lookup_table *table, FILE *out)
146 return for_lookup_table_entry(table, write_lookup_table_entry, out);
149 /* Unlinks and frees an entry from a lookup table. */
150 static inline void lookup_table_remove(struct lookup_table *table,
151 struct lookup_table_entry *lte)
153 lookup_table_unlink(table, lte);
154 free_lookup_table_entry(lte);
157 static inline struct resource_entry* wim_metadata_resource_entry(WIMStruct *w)
159 return &w->image_metadata[w->current_image - 1].
160 lookup_table_entry->resource_entry;