]> wimlib.net Git - wimlib/blobdiff - src/lookup_table.h
ntfs-capture.c: Do no-op reparse-point fixups
[wimlib] / src / lookup_table.h
index 81cb50a54fdce86a9bb3bf4d8d1b7dc8a838aa39..921a47c3e627fdb968ee9d6a7e48a66d4afbb04c 100644 (file)
@@ -40,7 +40,7 @@ struct ntfs_location {
        tchar *path;
        utf16lechar *stream_name;
        u16 stream_name_nchars;
-       struct _ntfs_volume **ntfs_vol_p;
+       struct _ntfs_volume *ntfs_vol;
        bool is_reparse_point;
 };
 #endif
@@ -63,11 +63,11 @@ enum resource_location {
         * WIM file will be pointed to by the @wim member. */
        RESOURCE_IN_WIM,
 
+#ifndef __WIN32__
        /* The stream resource is located in an external file.  The name of the
-        * file will be provided by @file_on_disk member.  In addition, if
-        * @file_on_disk_fp is not NULL, it will be an open FILE * to the file.
-        * */
+        * file will be provided by @file_on_disk member. */
        RESOURCE_IN_FILE_ON_DISK,
+#endif
 
        /* The stream resource is directly attached in an in-memory buffer
         * pointed to by @attached_buffer. */
@@ -135,11 +135,20 @@ struct wim_lookup_table_entry {
         */
        u16 part_number;
 
-       /* See enum resource_location above */
+       /* One of the `enum resource_location' values documented above. */
        u16 resource_location : 5;
+
+       /* 1 if this stream is a unique size (only set while writing streams). */
        u8 unique_size : 1;
+
+       /* 1 if this stream has not had a SHA1 message digest calculated for it
+        * yet */
        u8 unhashed : 1;
 
+       u8 deferred : 1;
+
+       u8 no_progress : 1;
+
        /* (On-disk field)
         * Number of times this lookup table entry is referenced by dentries.
         * Unfortunately, this field is not always set correctly in Microsoft's
@@ -159,24 +168,27 @@ struct wim_lookup_table_entry {
                 * table. */
                size_t hash_short;
 
-               /* 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 **back_ptr;
+               /* Unhashed entries only (unhashed == 1): these variables make
+                * it possible to find the pointer to this 'struct
+                * wim_lookup_table_entry' contained in either 'struct
+                * wim_ads_entry' or 'struct wim_inode'.  There can be at most 1
+                * such pointer, as we can only join duplicate streams after
+                * they have been hashed.  */
+               struct {
+                       struct wim_inode *back_inode;
+                       u32 back_stream_id;
+               };
        };
 
        /* 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. */
+        * whenever the stream pointed to by this lookup table entry needs to be
+        * written.  The stream 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 {
-               void *resource_loc_private;
                WIMStruct *wim;
                tchar *file_on_disk;
                void *attached_buffer;
@@ -188,17 +200,16 @@ struct wim_lookup_table_entry {
        #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;
-
+       /* Actual reference count to this stream (only used while
+        * verifying an image). */
        u32 real_refcnt;
 
        union {
-               #ifdef WITH_FUSE
+       #ifdef WITH_FUSE
+               /* Number of times this stream has been opened (used only during
+                * mounting) */
                u16 num_opened_fds;
-               #endif
+       #endif
 
                /* This field is used for the special hardlink or symlink image
                 * extraction mode.   In these mode, all identical files are linked
@@ -210,14 +221,17 @@ struct wim_lookup_table_entry {
        union {
                /* When a WIM file is written, @output_resource_entry is filled
                 * in with the resource entry for the output WIM.  This will not
-                * necessarily be the same as the @resource_entry since: - The
-                * stream may have a different offset in the new WIM - The
-                * stream may have a different compressed size in the new WIM if
-                * the compression type changed
+                * necessarily be the same as the @resource_entry since:
+                * - The stream may have a different offset in the new WIM
+                * - The stream may have a different compressed size in the new
+                *   WIM if the compression type changed
                 */
                struct resource_entry output_resource_entry;
 
-               struct list_head msg_list;
+               struct {
+                       struct list_head msg_list;
+                       struct list_head being_compressed_list;
+               };
                struct list_head inode_list;
 
                struct {
@@ -231,8 +245,9 @@ struct wim_lookup_table_entry {
        union {
                struct list_head unhashed_list;
                struct list_head swm_stream_list;
+               struct list_head lookup_table_list;
                struct list_head extraction_list;
-               struct list_head new_stream_list;
+               struct list_head export_stream_list;
        };
 };
 
@@ -270,10 +285,12 @@ wim_resource_compression_type(const struct wim_lookup_table_entry *lte)
 static inline bool
 lte_filename_valid(const struct wim_lookup_table_entry *lte)
 {
-       return lte->resource_location == RESOURCE_IN_FILE_ON_DISK
+       return 0
        #ifdef __WIN32__
                || lte->resource_location == RESOURCE_WIN32
                || lte->resource_location == RESOURCE_WIN32_ENCRYPTED
+       #else
+               || lte->resource_location == RESOURCE_IN_FILE_ON_DISK
        #endif
        #ifdef WITH_FUSE
                || lte->resource_location == RESOURCE_IN_STAGING_FILE
@@ -290,6 +307,11 @@ read_lookup_table(WIMStruct *w);
 extern int
 write_lookup_table(WIMStruct *w, int image, struct resource_entry *out_res_entry);
 
+extern int
+write_lookup_table_from_stream_list(struct list_head *stream_list,
+                                   int out_fd,
+                                   struct resource_entry *out_res_entry);
+
 extern void
 free_lookup_table(struct wim_lookup_table *table);
 
@@ -300,6 +322,7 @@ lookup_table_insert(struct wim_lookup_table *table, struct wim_lookup_table_entr
 static inline void
 lookup_table_unlink(struct wim_lookup_table *table, struct wim_lookup_table_entry *lte)
 {
+       wimlib_assert(!lte->unhashed);
        hlist_del(&lte->hash_list);
        wimlib_assert(table->num_entries != 0);
        table->num_entries--;
@@ -363,9 +386,6 @@ inode_resolve_ltes(struct wim_inode *inode, struct wim_lookup_table *table);
 extern void
 inode_unresolve_ltes(struct wim_inode *inode);
 
-extern int
-write_lookup_table_entry(struct wim_lookup_table_entry *lte, void *__out);
-
 static inline struct wim_lookup_table_entry *
 inode_stream_lte_resolved(const struct wim_inode *inode, unsigned stream_idx)
 {
@@ -446,34 +466,12 @@ inode_stream_name_nbytes(const struct wim_inode *inode, unsigned stream_idx)
                return inode->i_ads_entries[stream_idx - 1].stream_name_nbytes;
 }
 
-static inline struct wim_lookup_table_entry *
-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_nbytes(inode, i) == 0 &&
-                   !is_zero_hash(inode_stream_hash_resolved(inode, i)))
-               {
-                       return inode_stream_lte_resolved(inode, i);
-               }
-       }
-       return NULL;
-}
+extern struct wim_lookup_table_entry *
+inode_unnamed_lte_resolved(const struct wim_inode *inode);
 
-static inline struct wim_lookup_table_entry *
+extern struct wim_lookup_table_entry *
 inode_unnamed_lte_unresolved(const struct wim_inode *inode,
-                            const struct wim_lookup_table *table)
-{
-       wimlib_assert(!inode->i_resolved);
-       for (unsigned i = 0; i <= inode->i_num_ads; i++) {
-               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);
-               }
-       }
-       return NULL;
-}
+                            const struct wim_lookup_table *table);
 
 extern struct wim_lookup_table_entry *
 inode_unnamed_lte(const struct wim_inode *inode, const struct wim_lookup_table *table);
@@ -485,12 +483,21 @@ 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 **back_ptr)
+                            struct wim_inode *back_inode,
+                            u32 back_stream_id)
 {
        lte->unhashed = 1;
+       lte->back_inode = back_inode;
+       lte->back_stream_id = back_stream_id;
        list_add_tail(&lte->unhashed_list, table->unhashed_streams);
-       lte->back_ptr = back_ptr;
-       *back_ptr = lte;
 }
 
+extern int
+hash_unhashed_stream(struct wim_lookup_table_entry *lte,
+                    struct wim_lookup_table *lookup_table,
+                    struct wim_lookup_table_entry **lte_ret);
+
+extern struct wim_lookup_table_entry **
+retrieve_lte_pointer(struct wim_lookup_table_entry *lte);
+
 #endif