]> wimlib.net Git - wimlib/blobdiff - src/lookup_table.h
split, join: Read input WIM(s) sequentially
[wimlib] / src / lookup_table.h
index 242e2c1b87f04863ee26ba33a0daea66ddf29475..eacd9aa4596dfae4441de5ec9fb338f2973f1048 100644 (file)
 #define LOOKUP_FLAG_ADS_OK             0x00000001
 #define LOOKUP_FLAG_DIRECTORY_OK       0x00000002
 
-/* Not yet used */
-//#define LOOKUP_FLAG_FOLLOW_SYMLINKS  0x00000004
+#ifdef __WIN32__
+#include <windef.h>
+#endif
 
 
-/* A lookup table that is used to translate the hash codes of dentries into the
- * offsets and sizes of uncompressed or compressed file resources.  It is
- * implemented as a hash table. */
+/* The lookup table of a WIM file maps SHA1 message digests to streams of data.
+ * Here, the in-memory structure is implemented as a hash table.
+ *
+ * Given a SHA1 message digest, the mapped-to stream is specified by an offset
+ * in the WIM, an uncompressed and compressed size, and resource flags (see
+ * 'struct resource_entry').  But, we associate additional information, such as
+ * a reference count, with each stream, so the actual mapping is from SHA1
+ * message digests to 'struct wim_lookup_table_entry's, each of which contains
+ * an embedded 'struct resource_entry'.
+ *
+ * Note: Everything will break horribly if there is a SHA1 collision.
+ */
 struct wim_lookup_table {
        struct hlist_head *array;
        u64 num_entries;
@@ -26,9 +36,9 @@ struct wim_lookup_table {
 
 #ifdef WITH_NTFS_3G
 struct ntfs_location {
-       char *path_utf8;
-       char *stream_name_utf16;
-       u16 stream_name_utf16_num_chars;
+       tchar *path;
+       utf16lechar *stream_name;
+       u16 stream_name_nchars;
        struct _ntfs_volume **ntfs_vol_p;
        bool is_reparse_point;
 };
@@ -71,6 +81,10 @@ enum resource_location {
         * point or not. @ntfs_loc points to a structure containing this
         * information. */
        RESOURCE_IN_NTFS_VOLUME,
+
+       /* Resource must be accessed using Win32 API (may be a named data
+        * stream) */
+       RESOURCE_WIN32,
 };
 
 /*
@@ -140,16 +154,16 @@ struct wim_lookup_table_entry {
                 * extraction mode.   In these mode, all identical files are linked
                 * together, and @extracted_file will be set to the filename of the
                 * first extracted file containing this stream.  */
-               char *extracted_file;
+               tchar *extracted_file;
        };
 
        /* Pointers to somewhere where the stream is actually located.  See the
         * comments for the @resource_location field above. */
        union {
                WIMStruct *wim;
-               char *file_on_disk;
-               char *staging_file_name;
-               u8 *attached_buffer;
+               tchar *file_on_disk;
+               tchar *staging_file_name;
+               void *attached_buffer;
        #ifdef WITH_NTFS_3G
                struct ntfs_location *ntfs_loc;
        #endif
@@ -158,6 +172,7 @@ struct wim_lookup_table_entry {
                /* @file_on_disk_fp and @attr are both used to cache file/stream
                 * handles so we don't have re-open them on every read */
 
+
                /* Valid iff resource_location == RESOURCE_IN_FILE_ON_DISK */
                FILE *file_on_disk_fp;
        #ifdef WITH_NTFS_3G
@@ -165,6 +180,10 @@ struct wim_lookup_table_entry {
                struct _ntfs_attr *attr;
        #endif
 
+       #ifdef __WIN32__
+               HANDLE win32_file_on_disk_fp;
+       #endif
+
                /* Pointer to inode that contains the opened file descriptors to
                 * this stream (valid iff resource_location ==
                 * RESOURCE_IN_STAGING_FILE) */
@@ -242,8 +261,8 @@ extern int
 read_lookup_table(WIMStruct *w);
 
 extern int
-write_lookup_table(struct wim_lookup_table *table, FILE *out,
-                  struct resource_entry *out_res_entry);
+write_lookup_table(WIMStruct *w, int image, struct resource_entry *out_res_entry);
+
 extern void
 free_lookup_table(struct wim_lookup_table *table);
 
@@ -255,6 +274,7 @@ static inline void
 lookup_table_unlink(struct wim_lookup_table *table, struct wim_lookup_table_entry *lte)
 {
        hlist_del(&lte->hash_list);
+       wimlib_assert(table->num_entries != 0);
        table->num_entries--;
 }
 
@@ -265,7 +285,8 @@ extern struct wim_lookup_table_entry *
 clone_lookup_table_entry(const struct wim_lookup_table_entry *lte);
 
 extern void
-print_lookup_table_entry(const struct wim_lookup_table_entry *entry);
+print_lookup_table_entry(const struct wim_lookup_table_entry *entry,
+                        FILE *out);
 
 extern void
 free_lookup_table_entry(struct wim_lookup_table_entry *lte);
@@ -275,11 +296,20 @@ for_lookup_table_entry(struct wim_lookup_table *table,
                       int (*visitor)(struct wim_lookup_table_entry *, void *),
                       void *arg);
 
+extern int
+sort_stream_list_by_wim_position(struct list_head *stream_list);
+
+extern int
+for_lookup_table_entry_pos_sorted(struct wim_lookup_table *table,
+                                 int (*visitor)(struct wim_lookup_table_entry *,
+                                                void *),
+                                 void *arg);
+
 extern struct wim_lookup_table_entry *
 __lookup_resource(const struct wim_lookup_table *table, const u8 hash[]);
 
 extern int
-lookup_resource(WIMStruct *w, const char *path,
+lookup_resource(WIMStruct *w, const tchar *path,
                int lookup_flags, struct wim_dentry **dentry_ret,
                struct wim_lookup_table_entry **lte_ret, u16 *stream_idx_ret);
 
@@ -387,13 +417,13 @@ inode_stream_hash(const struct wim_inode *inode, unsigned stream_idx)
 }
 
 static inline u16
-inode_stream_name_len(const struct wim_inode *inode, unsigned stream_idx)
+inode_stream_name_nbytes(const struct wim_inode *inode, unsigned stream_idx)
 {
        wimlib_assert(stream_idx <= inode->i_num_ads);
        if (stream_idx == 0)
                return 0;
        else
-               return inode->i_ads_entries[stream_idx - 1].stream_name_len;
+               return inode->i_ads_entries[stream_idx - 1].stream_name_nbytes;
 }
 
 static inline struct wim_lookup_table_entry *
@@ -401,7 +431,7 @@ inode_unnamed_lte_resolved(const struct wim_inode *inode)
 {
        wimlib_assert(inode->i_resolved);
        for (unsigned i = 0; i <= inode->i_num_ads; i++) {
-               if (inode_stream_name_len(inode, i) == 0 &&
+               if (inode_stream_name_nbytes(inode, i) == 0 &&
                    !is_zero_hash(inode_stream_hash_resolved(inode, i)))
                {
                        return inode_stream_lte_resolved(inode, i);
@@ -416,7 +446,7 @@ inode_unnamed_lte_unresolved(const struct wim_inode *inode,
 {
        wimlib_assert(!inode->i_resolved);
        for (unsigned i = 0; i <= inode->i_num_ads; i++) {
-               if (inode_stream_name_len(inode, i) == 0 &&
+               if (inode_stream_name_nbytes(inode, i) == 0 &&
                    !is_zero_hash(inode_stream_hash_unresolved(inode, i)))
                {
                        return inode_stream_lte_unresolved(inode, i, table);