]> wimlib.net Git - wimlib/blob - include/wimlib/resource.h
wimlib.h: Fix typo
[wimlib] / include / wimlib / resource.h
1 #ifndef _WIMLIB_RESOURCE_H
2 #define _WIMLIB_RESOURCE_H
3
4 #include "wimlib/types.h"
5 #include "wimlib/callback.h"
6
7 struct wim_lookup_table_entry;
8 struct wim_image_metadata;
9
10 /* Metadata for a resource in a WIM file. */
11 struct resource_entry {
12         /* Size, in bytes, of the resource in the WIM file. */
13         u64 size  : 56;
14
15         /* Bitwise or of one or more of the WIM_RESHDR_FLAG_* flags. */
16         u64 flags : 8;
17
18         /* Offset, in bytes, of the resource in the WIM file. */
19         u64 offset;
20
21         /* Uncompressed size of the resource in the WIM file.  Is the same as
22          * @size if the resource is uncompressed. */
23         u64 original_size;
24 };
25
26 struct resource_entry_disk {
27         u8 size[7];
28         u8 flags;
29         le64 offset;
30         le64 original_size;
31 } _packed_attribute;
32
33 /* Flags for the `flags' field of the struct resource_entry structure. */
34
35 /* I haven't seen this flag used in any of the WIMs I have examined.  I assume
36  * it means that there are no references to the stream, so the space is free.
37  * However, even after deleting files from a WIM mounted with `imagex.exe
38  * /mountrw', I could not see this flag being used.  Either way, we don't
39  * actually use this flag for anything. */
40 #define WIM_RESHDR_FLAG_FREE            0x01
41
42 /* Indicates that the stream is a metadata resource for a WIM image. */
43 #define WIM_RESHDR_FLAG_METADATA        0x02
44
45 /* Indicates that the stream is compressed. */
46 #define WIM_RESHDR_FLAG_COMPRESSED      0x04
47
48 /* I haven't seen this flag used in any of the WIMs I have examined.  Perhaps it
49  * means that a stream could possibly be split among multiple split WIM parts.
50  * However, `imagex.exe /split' does not seem to create any WIMs like this.
51  * Either way, we don't actually use this flag for anything.  */
52 #define WIM_RESHDR_FLAG_SPANNED         0x08
53
54 /* Nonzero if a struct resource_entry indicates a compressed resource. */
55 static inline int
56 resource_is_compressed(const struct resource_entry *entry)
57 {
58         return (entry->flags & WIM_RESHDR_FLAG_COMPRESSED);
59 }
60
61 #if 1
62 #  define copy_resource_entry(dst, src) memcpy(dst, src, sizeof(struct resource_entry))
63 #  define zero_resource_entry(entry) memset(entry, 0, sizeof(struct resource_entry))
64 #else
65 static inline void
66 copy_resource_entry(struct resource_entry *dst,
67                     const struct resource_entry *src)
68 {
69         BUILD_BUG_ON(sizeof(struct resource_entry) != 24);
70         ((u64*)dst)[0] = ((u64*)src)[0];
71         ((u64*)dst)[1] = ((u64*)src)[1];
72         ((u64*)dst)[2] = ((u64*)src)[2];
73 }
74
75 static inline void
76 zero_resource_entry(struct resource_entry *entry)
77 {
78         BUILD_BUG_ON(sizeof(struct resource_entry) != 24);
79         ((u64*)entry)[0] = 0;
80         ((u64*)entry)[1] = 0;
81         ((u64*)entry)[2] = 0;
82 }
83 #endif
84
85 #define WIMLIB_RESOURCE_FLAG_RAW                0x1
86 #define WIMLIB_RESOURCE_FLAG_RECOMPRESS         0x2
87
88 extern int
89 read_resource_prefix(const struct wim_lookup_table_entry *lte,
90                      u64 size, consume_data_callback_t cb, void *ctx_or_buf,
91                      int flags);
92
93 extern void
94 get_resource_entry(const struct resource_entry_disk *disk_entry,
95                    struct resource_entry *entry);
96
97 extern void
98 put_resource_entry(const struct resource_entry *entry,
99                    struct resource_entry_disk *disk_entry);
100
101 extern int
102 read_partial_wim_resource_into_buf(const struct wim_lookup_table_entry *lte,
103                                    size_t size, u64 offset, void *buf);
104 extern int
105 read_full_resource_into_buf(const struct wim_lookup_table_entry *lte, void *buf);
106
107 extern int
108 write_wim_resource(struct wim_lookup_table_entry *lte, int out_fd,
109                    int out_ctype, struct resource_entry *out_res_entry,
110                    int flags);
111
112 extern int
113 extract_wim_resource(const struct wim_lookup_table_entry *lte,
114                      u64 size,
115                      consume_data_callback_t extract_chunk,
116                      void *extract_chunk_arg);
117
118 extern int
119 extract_wim_resource_to_fd(const struct wim_lookup_table_entry *lte,
120                            int fd, u64 size);
121
122 extern int
123 sha1_resource(struct wim_lookup_table_entry *lte);
124
125 extern int
126 copy_resource(struct wim_lookup_table_entry *lte, void *w);
127
128 extern int
129 read_metadata_resource(WIMStruct *w,
130                        struct wim_image_metadata *image_metadata);
131
132 extern int
133 write_metadata_resource(WIMStruct *w);
134
135 #endif /* _WIMLIB_RESOURCE_H */