]> wimlib.net Git - wimlib/blobdiff - src/lookup_table.h
Fixes, comments
[wimlib] / src / lookup_table.h
index dad230f7ad58ab3443ad66dbd207e758c9aee05c..633c874e17d1f7d1fc8ec03e6c41f722ddd135ff 100644 (file)
@@ -32,6 +32,7 @@ struct wim_lookup_table {
        struct hlist_head *array;
        u64 num_entries;
        u64 capacity;
+       struct list_head *unhashed_streams;
 };
 
 #ifdef WITH_NTFS_3G
@@ -68,23 +69,35 @@ enum resource_location {
         * */
        RESOURCE_IN_FILE_ON_DISK,
 
-       /* The stream resource is located in an external file in the staging
-        * directory for a read-write mount.  */
-       RESOURCE_IN_STAGING_FILE,
-
        /* The stream resource is directly attached in an in-memory buffer
         * pointed to by @attached_buffer. */
        RESOURCE_IN_ATTACHED_BUFFER,
 
+#ifdef WITH_FUSE
+       /* The stream resource is located in an external file in the staging
+        * directory for a read-write mount.  */
+       RESOURCE_IN_STAGING_FILE,
+#endif
+
+#ifdef WITH_NTFS_3G
        /* The stream resource is located in an NTFS volume.  It is identified
         * by volume, filename, data stream name, and by whether it is a reparse
         * point or not. @ntfs_loc points to a structure containing this
         * information. */
        RESOURCE_IN_NTFS_VOLUME,
+#endif
 
+#ifdef __WIN32__
        /* Resource must be accessed using Win32 API (may be a named data
         * stream) */
        RESOURCE_WIN32,
+
+       /* Windows only: the file is on disk in the file named @file_on_disk,
+        * but the file is encrypted and must be read using special functions.
+        * */
+       RESOURCE_WIN32_ENCRYPTED,
+#endif
+
 };
 
 /*
@@ -123,7 +136,9 @@ struct wim_lookup_table_entry {
        u16 part_number;
 
        /* See enum resource_location above */
-       u16 resource_location;
+       u16 resource_location : 5;
+       u8 unique_size : 1;
+       u8 unhashed : 1;
 
        /* (On-disk field)
         * Number of times this lookup table entry is referenced by dentries.
@@ -143,20 +158,21 @@ struct wim_lookup_table_entry {
                 * the full 20 byte hash just to insert the entry in a hash
                 * table. */
                size_t hash_short;
-       };
 
-       union {
-               #ifdef WITH_FUSE
-               u16 num_opened_fds;
-               #endif
-
-               /* This field is used for the special hardlink or symlink image
-                * 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.  */
-               tchar *extracted_file;
+               /* Unhashed entries only (unhashed == 1): this points directly
+                * to the pointer to this 'struct wim_lookup_table_entry'
+                * contained in a 'struct wim_ads_entry' or 'struct wim_inode'.
+                * */
+               struct wim_lookup_table_entry **my_ptr;
        };
 
+       /* When a WIM file is written, out_refcnt starts at 0 and is incremented
+        * whenever the file resource pointed to by this lookup table entry
+        * needs to be written.  The file resource only need to be written when
+        * out_refcnt is nonzero, since otherwise it is not referenced by any
+        * dentries. */
+       u32 out_refcnt;
+
        /* Pointers to somewhere where the stream is actually located.  See the
         * comments for the @resource_location field above. */
        union {
@@ -168,37 +184,26 @@ struct wim_lookup_table_entry {
                struct ntfs_location *ntfs_loc;
        #endif
        };
-       union {
-               /* @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 */
 
+       /* Pointer to inode that contains the opened file descriptors to
+        * this stream (valid iff resource_location ==
+        * RESOURCE_IN_STAGING_FILE) */
+       struct wim_inode *lte_inode;
 
-               /* Valid iff resource_location == RESOURCE_IN_FILE_ON_DISK */
-               FILE *file_on_disk_fp;
-       #ifdef WITH_NTFS_3G
-               /* Valid iff resource_location == RESOURCE_IN_NTFS_VOLUME */
-               struct _ntfs_attr *attr;
-       #endif
+       u32 real_refcnt;
 
-       #ifdef __WIN32__
-               HANDLE win32_file_on_disk_fp;
-       #endif
+       union {
+               #ifdef WITH_FUSE
+               u16 num_opened_fds;
+               #endif
 
-               /* Pointer to inode that contains the opened file descriptors to
-                * this stream (valid iff resource_location ==
-                * RESOURCE_IN_STAGING_FILE) */
-               struct wim_inode *lte_inode;
+               /* This field is used for the special hardlink or symlink image
+                * 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.  */
+               tchar *extracted_file;
        };
 
-       /* When a WIM file is written, out_refcnt starts at 0 and is incremented
-        * whenever the file resource pointed to by this lookup table entry
-        * needs to be written.  The file resource only need to be written when
-        * out_refcnt is nonzero, since otherwise it is not referenced by any
-        * dentries. */
-       u32 out_refcnt;
-
-       u32 real_refcnt;
-
        union {
                /* When a WIM file is written, @output_resource_entry is filled
                 * in with the resource entry for the output WIM.  This will not
@@ -211,6 +216,11 @@ struct wim_lookup_table_entry {
 
                struct list_head msg_list;
                struct list_head inode_list;
+
+               struct {
+                       struct hlist_node hash_list_2;
+                       struct list_head write_streams_list;
+               };
        };
 
        /* List of lookup table entries that correspond to streams that have
@@ -219,7 +229,11 @@ struct wim_lookup_table_entry {
         *
         * This field is also used to make other lists of lookup table entries.
         * */
-       struct list_head staging_list;
+       union {
+               struct list_head unhashed_list;
+               struct list_head staging_list;
+               struct list_head extraction_list;
+       };
 };
 
 static inline u64
@@ -253,6 +267,19 @@ wim_resource_compression_type(const struct wim_lookup_table_entry *lte)
        return wimlib_get_compression_type(lte->wim);
 }
 
+static inline bool
+lte_filename_valid(const struct wim_lookup_table_entry *lte)
+{
+       return lte->resource_location == RESOURCE_IN_FILE_ON_DISK
+       #ifdef __WIN32__
+               || lte->resource_location == RESOURCE_WIN32
+               || lte->resource_location == RESOURCE_WIN32_ENCRYPTED
+       #endif
+       #ifdef WITH_FUSE
+               || lte->resource_location == RESOURCE_IN_STAGING_FILE
+       #endif
+               ;
+}
 
 extern struct wim_lookup_table *
 new_lookup_table(size_t capacity);
@@ -274,6 +301,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--;
 }
 
@@ -295,6 +323,15 @@ for_lookup_table_entry(struct wim_lookup_table *table,
                       int (*visitor)(struct wim_lookup_table_entry *, void *),
                       void *arg);
 
+extern int
+cmp_streams_by_wim_position(const void *p1, const void *p2);
+
+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[]);
 
@@ -329,13 +366,6 @@ inode_unresolve_ltes(struct wim_inode *inode);
 extern int
 write_lookup_table_entry(struct wim_lookup_table_entry *lte, void *__out);
 
-static inline struct resource_entry*
-wim_metadata_resource_entry(WIMStruct *w)
-{
-       return &w->image_metadata[
-                       w->current_image - 1].metadata_lte->resource_entry;
-}
-
 static inline struct wim_lookup_table_entry *
 inode_stream_lte_resolved(const struct wim_inode *inode, unsigned stream_idx)
 {
@@ -451,4 +481,19 @@ inode_unnamed_lte(const struct wim_inode *inode, const struct wim_lookup_table *
 extern u64
 lookup_table_total_stream_size(struct wim_lookup_table *table);
 
+
+static inline void
+lookup_table_insert_unhashed(struct wim_lookup_table *table,
+                            struct wim_lookup_table_entry *lte,
+                            struct wim_lookup_table_entry **my_ptr)
+{
+       lte->unhashed = 1;
+       list_add_tail(&lte->unhashed_list, table->unhashed_streams);
+       lte->my_ptr = my_ptr;
+       *my_ptr = lte;
+}
+
+extern void
+free_lte_list(struct list_head *list);
+
 #endif