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