#endif
struct apply_args {
- WIMStruct *w;
+ WIMStruct *wim;
/* Directory to which we're extracting the WIM image or directory tree,
* in user-specified form (may be slightly altered) */
set_dentry_name(struct wim_dentry *dentry, const tchar *new_name);
extern struct wim_dentry *
-get_dentry(struct WIMStruct *w, const tchar *path);
+get_dentry(struct WIMStruct *wim, const tchar *path);
extern struct wim_inode *
-wim_pathname_to_inode(struct WIMStruct *w, const tchar *path);
+wim_pathname_to_inode(struct WIMStruct *wim, const tchar *path);
extern struct wim_dentry *
get_dentry_child_with_name(const struct wim_dentry *dentry,
size_t name_nbytes);
extern struct wim_dentry *
-get_parent_dentry(struct WIMStruct *w, const tchar *path);
+get_parent_dentry(struct WIMStruct *wim, const tchar *path);
extern int
print_dentry(struct wim_dentry *dentry, void *lookup_table);
wimlib_progress_func_t progress_func);
extern int
-check_wim_integrity(WIMStruct *w, wimlib_progress_func_t progress_func);
+check_wim_integrity(WIMStruct *wim, wimlib_progress_func_t progress_func);
#endif /* _WIMLIB_INTEGRITY_H */
new_lookup_table(size_t capacity) _malloc_attribute;
extern int
-read_lookup_table(WIMStruct *w);
+read_lookup_table(WIMStruct *wim);
extern int
-write_lookup_table(WIMStruct *w, int image, struct resource_entry *out_res_entry);
+write_lookup_table(WIMStruct *wim, int image, struct resource_entry *out_res_entry);
extern int
write_lookup_table_from_stream_list(struct list_head *stream_list,
__lookup_resource(const struct wim_lookup_table *table, const u8 hash[]);
extern int
-lookup_resource(WIMStruct *w, const tchar *path,
+lookup_resource(WIMStruct *wim, const tchar *path,
int lookup_flags, struct wim_dentry **dentry_ret,
struct wim_lookup_table_entry **lte_ret, u16 *stream_idx_ret);
};
static inline struct wim_image_metadata *
-wim_get_current_image_metadata(WIMStruct *w)
+wim_get_current_image_metadata(WIMStruct *wim)
{
- return w->image_metadata[w->current_image - 1];
+ return wim->image_metadata[wim->current_image - 1];
}
static inline const struct wim_image_metadata *
-wim_get_const_current_image_metadata(const WIMStruct *w)
+wim_get_const_current_image_metadata(const WIMStruct *wim)
{
- return w->image_metadata[w->current_image - 1];
+ return wim->image_metadata[wim->current_image - 1];
}
static inline struct wim_dentry *
-wim_root_dentry(WIMStruct *w)
+wim_root_dentry(WIMStruct *wim)
{
- return wim_get_current_image_metadata(w)->root_dentry;
+ return wim_get_current_image_metadata(wim)->root_dentry;
}
static inline struct wim_security_data *
-wim_security_data(WIMStruct *w)
+wim_security_data(WIMStruct *wim)
{
- return wim_get_current_image_metadata(w)->security_data;
+ return wim_get_current_image_metadata(wim)->security_data;
}
static inline const struct wim_security_data *
-wim_const_security_data(const WIMStruct *w)
+wim_const_security_data(const WIMStruct *wim)
{
- return wim_get_const_current_image_metadata(w)->security_data;
+ return wim_get_const_current_image_metadata(wim)->security_data;
}
/* Iterate over each inode in a WIM image that has not yet been hashed */
struct wim_lookup_table *table);
extern int
-append_image_metadata(WIMStruct *w, struct wim_image_metadata *imd);
+append_image_metadata(WIMStruct *wim, struct wim_image_metadata *imd);
extern struct wim_image_metadata *
new_image_metadata(void);
sha1_resource(struct wim_lookup_table_entry *lte);
extern int
-copy_resource(struct wim_lookup_table_entry *lte, void *w);
+copy_resource(struct wim_lookup_table_entry *lte, void *wim);
extern int
-read_metadata_resource(WIMStruct *w,
+read_metadata_resource(WIMStruct *wim,
struct wim_image_metadata *image_metadata);
extern int
-write_metadata_resource(WIMStruct *w);
+write_metadata_resource(WIMStruct *wim);
#endif /* _WIMLIB_RESOURCE_H */
#include "wimlib/types.h"
extern int
-verify_swm_set(WIMStruct *w,
+verify_swm_set(WIMStruct *wim,
WIMStruct **additional_swms, unsigned num_additional_swms);
extern void
-merge_lookup_tables(WIMStruct *w,
+merge_lookup_tables(WIMStruct *wim,
WIMStruct **additional_swms, unsigned num_additional_swms);
extern void
rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to);
extern int
-select_wim_image(WIMStruct *w, int image);
+select_wim_image(WIMStruct *wim, int image);
extern int
-for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *));
+for_image(WIMStruct *wim, int image, int (*visitor)(WIMStruct *));
extern int
-wim_checksum_unhashed_streams(WIMStruct *w);
+wim_checksum_unhashed_streams(WIMStruct *wim);
extern int
-reopen_wim(WIMStruct *w);
+reopen_wim(WIMStruct *wim);
extern int
-close_wim(WIMStruct *w);
+close_wim(WIMStruct *wim);
extern int
can_modify_wim(WIMStruct *wim);
#define WIMLIB_WRITE_MASK_PUBLIC 0x1fffffff
extern int
-begin_write(WIMStruct *w, const tchar *path, int write_flags);
+begin_write(WIMStruct *wim, const tchar *path, int write_flags);
extern void
-close_wim_writable(WIMStruct *w);
+close_wim_writable(WIMStruct *wim);
extern int
-finish_write(WIMStruct *w, int image, int write_flags,
+finish_write(WIMStruct *wim, int image, int write_flags,
wimlib_progress_func_t progress_func);
#if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
extern int
-lock_wim(WIMStruct *w, int fd);
+lock_wim(WIMStruct *wim, int fd);
#else
static inline int
-lock_wim(WIMStruct *w, int fd)
+lock_wim(WIMStruct *wim, int fd)
{
return 0;
}
const tchar *dest_image_description);
extern size_t
-xml_get_max_image_name_len(const WIMStruct *w);
+xml_get_max_image_name_len(const WIMStruct *wim);
extern void
-xml_update_image_info(WIMStruct *w, int image);
+xml_update_image_info(WIMStruct *wim, int image);
extern void
xml_delete_image(struct wim_info **wim_info_p, int image);
extern int
-xml_add_image(WIMStruct *w, const tchar *name);
+xml_add_image(WIMStruct *wim, const tchar *name);
extern void
free_wim_info(struct wim_info *info);
memset(&args, 0, sizeof(args));
- args.w = wim;
+ args.wim = wim;
args.target = target;
args.target_nchars = tstrlen(target);
args.extract_flags = extract_flags;
{WIM_HDR_FLAG_COMPRESS_XPRESS, "COMPRESS_XPRESS"},
};
-/* Prints information from the header of the WIM file associated with @w. */
+/* Prints information from the header of the WIM file associated with @wim. */
WIMLIBAPI void
-wimlib_print_header(const WIMStruct *w)
+wimlib_print_header(const WIMStruct *wim)
{
- const struct wim_header *hdr = &w->hdr;
+ const struct wim_header *hdr = &wim->hdr;
tprintf(T("Magic Characters = MSWIM\\000\\000\\000\n"));
tprintf(T("Header Size = %u\n"), WIM_HEADER_DISK_SIZE);
tfputs (T("GUID = "), stdout);
print_byte_field(hdr->guid, WIM_GID_LEN, stdout);
tputchar(T('\n'));
- tprintf(T("Part Number = %hu\n"), w->hdr.part_number);
- tprintf(T("Total Parts = %hu\n"), w->hdr.total_parts);
+ tprintf(T("Part Number = %hu\n"), wim->hdr.part_number);
+ tprintf(T("Total Parts = %hu\n"), wim->hdr.total_parts);
tprintf(T("Image Count = %u\n"), hdr->image_count);
tprintf(T("Lookup Table Size = %"PRIu64"\n"),
(u64)hdr->lookup_table_res_entry.size);
* ~10 MiB chunks of the WIM match up with the values given in the integrity
* table.
*
- * @w:
+ * @wim:
* The WIM, opened for reading, and with the header already read.
*
* @progress_func
* information.
*/
int
-check_wim_integrity(WIMStruct *w, wimlib_progress_func_t progress_func)
+check_wim_integrity(WIMStruct *wim, wimlib_progress_func_t progress_func)
{
int ret;
u64 bytes_to_check;
struct integrity_table *table;
u64 end_lookup_table_offset;
- if (w->hdr.integrity.offset == 0) {
+ if (wim->hdr.integrity.offset == 0) {
DEBUG("No integrity information.");
return WIM_INTEGRITY_NONEXISTENT;
}
- end_lookup_table_offset = w->hdr.lookup_table_res_entry.offset +
- w->hdr.lookup_table_res_entry.size;
+ end_lookup_table_offset = wim->hdr.lookup_table_res_entry.offset +
+ wim->hdr.lookup_table_res_entry.size;
if (end_lookup_table_offset < WIM_HEADER_DISK_SIZE) {
ERROR("WIM lookup table ends before WIM header ends!");
bytes_to_check = end_lookup_table_offset - WIM_HEADER_DISK_SIZE;
- ret = read_integrity_table(&w->hdr.integrity, w->in_fd,
+ ret = read_integrity_table(&wim->hdr.integrity, wim->in_fd,
bytes_to_check, &table);
if (ret)
return ret;
- ret = verify_integrity(w->in_fd, w->filename, table,
+ ret = verify_integrity(wim->in_fd, wim->filename, table,
bytes_to_check, progress_func);
FREE(table);
return ret;
* image_metadata array).
*/
int
-read_lookup_table(WIMStruct *w)
+read_lookup_table(WIMStruct *wim)
{
int ret;
size_t num_entries;
const struct wim_lookup_table_entry_disk *disk_entry;
DEBUG("Reading lookup table: offset %"PRIu64", size %"PRIu64"",
- w->hdr.lookup_table_res_entry.offset,
- w->hdr.lookup_table_res_entry.original_size);
+ wim->hdr.lookup_table_res_entry.offset,
+ wim->hdr.lookup_table_res_entry.original_size);
- if (resource_is_compressed(&w->hdr.lookup_table_res_entry)) {
+ if (resource_is_compressed(&wim->hdr.lookup_table_res_entry)) {
ERROR("Didn't expect a compressed lookup table!");
ERROR("Ask the author to implement support for this.");
return WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE;
}
- num_entries = w->hdr.lookup_table_res_entry.size /
+ num_entries = wim->hdr.lookup_table_res_entry.size /
sizeof(struct wim_lookup_table_entry_disk);
table = new_lookup_table(num_entries * 2 + 1);
if (!table) {
return WIMLIB_ERR_NOMEM;
}
- w->current_image = 0;
- offset = w->hdr.lookup_table_res_entry.offset;
+ wim->current_image = 0;
+ offset = wim->hdr.lookup_table_res_entry.offset;
buf_entries_remaining = 0;
for (; num_entries != 0;
num_entries--, buf_entries_remaining--, disk_entry++)
entries_to_read = min(ARRAY_LEN(table_buf), num_entries);
bytes_to_read = entries_to_read * sizeof(struct wim_lookup_table_entry_disk);
- if (full_pread(w->in_fd, table_buf,
+ if (full_pread(wim->in_fd, table_buf,
bytes_to_read, offset) != bytes_to_read)
{
ERROR_WITH_ERRNO("Error reading lookup table "
goto out_free_lookup_table;
}
- cur_entry->wim = w;
+ cur_entry->wim = wim;
cur_entry->resource_location = RESOURCE_IN_WIM;
get_resource_entry(&disk_entry->resource_entry, &cur_entry->resource_entry);
cur_entry->part_number = le16_to_cpu(disk_entry->part_number);
copy_hash(cur_entry->hash, disk_entry->hash);
if (cur_entry->resource_entry.flags & WIM_RESHDR_FLAG_COMPRESSED)
- cur_entry->compression_type = w->compression_type;
+ cur_entry->compression_type = wim->compression_type;
else
BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_NONE != 0);
- if (cur_entry->part_number != w->hdr.part_number) {
+ if (cur_entry->part_number != wim->hdr.part_number) {
WARNING("A lookup table entry in part %hu of the WIM "
"points to part %hu (ignoring it)",
- w->hdr.part_number, cur_entry->part_number);
+ wim->hdr.part_number, cur_entry->part_number);
free_lookup_table_entry(cur_entry);
continue;
}
goto out_free_cur_entry;
}
- if (w->hdr.part_number != 1) {
+ if (wim->hdr.part_number != 1) {
WARNING("Ignoring metadata resource found in a "
"non-first part of the split WIM");
free_lookup_table_entry(cur_entry);
continue;
}
- if (w->current_image == w->hdr.image_count) {
+ if (wim->current_image == wim->hdr.image_count) {
WARNING("The WIM header says there are %u images "
"in the WIM, but we found more metadata "
"resources than this (ignoring the extra)",
- w->hdr.image_count);
+ wim->hdr.image_count);
free_lookup_table_entry(cur_entry);
continue;
}
* written in the XML data. */
DEBUG("Found metadata resource for image %u at "
"offset %"PRIu64".",
- w->current_image + 1,
+ wim->current_image + 1,
cur_entry->resource_entry.offset);
- w->image_metadata[
- w->current_image++]->metadata_lte = cur_entry;
+ wim->image_metadata[
+ wim->current_image++]->metadata_lte = cur_entry;
} else {
/* Lookup table entry for a stream that is not a
* metadata resource */
}
}
- if (w->hdr.part_number == 1 && w->current_image != w->hdr.image_count) {
+ if (wim->hdr.part_number == 1 && wim->current_image != wim->hdr.image_count) {
WARNING("The header of \"%"TS"\" says there are %u images in\n"
" the WIM, but we only found %d metadata resources! Acting as if\n"
" the header specified only %d images instead.",
- w->filename, w->hdr.image_count,
- w->current_image, w->current_image);
- for (int i = w->current_image; i < w->hdr.image_count; i++)
- put_image_metadata(w->image_metadata[i], NULL);
- w->hdr.image_count = w->current_image;
+ wim->filename, wim->hdr.image_count,
+ wim->current_image, wim->current_image);
+ for (int i = wim->current_image; i < wim->hdr.image_count; i++)
+ put_image_metadata(wim->image_metadata[i], NULL);
+ wim->hdr.image_count = wim->current_image;
}
DEBUG("Done reading lookup table.");
- w->lookup_table = table;
+ wim->lookup_table = table;
ret = 0;
goto out;
out_free_cur_entry:
out_free_lookup_table:
free_lookup_table(table);
out:
- w->current_image = 0;
+ wim->current_image = 0;
return ret;
}
/* Writes the WIM lookup table to the output file. */
int
-write_lookup_table(WIMStruct *w, int image, struct resource_entry *out_res_entry)
+write_lookup_table(WIMStruct *wim, int image, struct resource_entry *out_res_entry)
{
LIST_HEAD(stream_list);
int start_image;
if (image == WIMLIB_ALL_IMAGES) {
start_image = 1;
- end_image = w->hdr.image_count;
+ end_image = wim->hdr.image_count;
} else {
start_image = image;
end_image = image;
for (int i = start_image; i <= end_image; i++) {
struct wim_lookup_table_entry *metadata_lte;
- metadata_lte = w->image_metadata[i - 1]->metadata_lte;
+ metadata_lte = wim->image_metadata[i - 1]->metadata_lte;
metadata_lte->out_refcnt = 1;
metadata_lte->output_resource_entry.flags |= WIM_RESHDR_FLAG_METADATA;
append_lookup_table_entry(metadata_lte, &stream_list);
}
- for_lookup_table_entry(w->lookup_table,
+ for_lookup_table_entry(wim->lookup_table,
append_lookup_table_entry,
&stream_list);
return write_lookup_table_from_stream_list(&stream_list,
- w->out_fd,
+ wim->out_fd,
out_res_entry);
}
* This is only for pre-resolved inodes.
*/
int
-lookup_resource(WIMStruct *w,
+lookup_resource(WIMStruct *wim,
const tchar *path,
int lookup_flags,
struct wim_dentry **dentry_ret,
}
}
- dentry = get_dentry(w, path);
+ dentry = get_dentry(wim, path);
if (p)
*p = T(':');
if (!dentry)
inode = dentry->d_inode;
if (!inode->i_resolved)
- if (inode_resolve_ltes(inode, w->lookup_table))
+ if (inode_resolve_ltes(inode, wim->lookup_table))
return -EIO;
if (!(lookup_flags & LOOKUP_FLAG_DIRECTORY_OK)
* end-of-directory is signaled by a directory entry of length '0', really of
* length 8, because that's how long the 'length' field is.
*
- * @w: Pointer to the WIMStruct for the WIM file.
+ * @wim: Pointer to the WIMStruct for the WIM file.
*
* @imd: Pointer to the image metadata structure for the image whose
* metadata resource we are reading. Its `metadata_lte' member
/* Write the metadata resource for the current WIM image. */
int
-write_metadata_resource(WIMStruct *w)
+write_metadata_resource(WIMStruct *wim)
{
u8 *buf;
u8 *p;
struct wim_security_data *sd;
struct wim_image_metadata *imd;
- wimlib_assert(w->out_fd != -1);
- wimlib_assert(w->current_image != WIMLIB_NO_IMAGE);
+ wimlib_assert(wim->out_fd != -1);
+ wimlib_assert(wim->current_image != WIMLIB_NO_IMAGE);
DEBUG("Writing metadata resource for image %d (offset = %"PRIu64")",
- w->current_image, filedes_offset(w->out_fd));
+ wim->current_image, filedes_offset(wim->out_fd));
- imd = w->image_metadata[w->current_image - 1];
+ imd = wim->image_metadata[wim->current_image - 1];
root = imd->root_dentry;
sd = imd->security_data;
/* Get the lookup table entry for the metadata resource so we can update
* it. */
- lte = wim_get_current_image_metadata(w)->metadata_lte;
+ lte = wim_get_current_image_metadata(wim)->metadata_lte;
/* Write the metadata resource to the output WIM using the proper
* compression type. The lookup table entry for the metadata resource
* is updated. */
ret = write_wim_resource_from_buffer(buf, metadata_original_size,
- w->out_fd,
- w->compression_type,
+ wim->out_fd,
+ wim->compression_type,
<e->output_resource_entry,
lte->hash);
/* Note that although the SHA1 message digest of the metadata resource
{
int ret;
struct wim_lookup_table_entry *lte, *tmp;
- WIMStruct *w = ctx->wim;
+ WIMStruct *wim = ctx->wim;
struct wim_image_metadata *imd = wim_get_current_image_metadata(ctx->wim);
DEBUG("Closing all staging file descriptors.");
}
}
- xml_update_image_info(w, w->current_image);
- ret = wimlib_overwrite(w, write_flags, 0, progress_func);
+ xml_update_image_info(wim, wim->current_image);
+ ret = wimlib_overwrite(wim, write_flags, 0, progress_func);
if (ret)
ERROR("Failed to commit changes to mounted WIM image");
return ret;
struct wim_dentry *from_dentry, *from_dentry_parent;
const char *link_name;
struct wim_inode *inode;
- WIMStruct *w = wimfs_get_WIMStruct();
+ WIMStruct *wim = wimfs_get_WIMStruct();
int ret;
- inode = wim_pathname_to_inode(w, to);
+ inode = wim_pathname_to_inode(wim, to);
if (!inode)
return -errno;
FILE_ATTRIBUTE_REPARSE_POINT))
return -EPERM;
- from_dentry_parent = get_parent_dentry(w, from);
+ from_dentry_parent = get_parent_dentry(wim, from);
if (!from_dentry_parent)
return -errno;
if (!dentry_is_directory(from_dentry_parent))
int ret;
struct wimfs_fd *fd = NULL;
struct wimfs_context *ctx = wimfs_get_context();
- WIMStruct *w = ctx->wim;
+ WIMStruct *wim = ctx->wim;
- inode = wim_pathname_to_inode(w, path);
+ inode = wim_pathname_to_inode(wim, path);
if (!inode)
return -errno;
if (!inode_is_directory(inode))
wimfs_rmdir(const char *path)
{
struct wim_dentry *dentry;
- WIMStruct *w = wimfs_get_WIMStruct();
+ WIMStruct *wim = wimfs_get_WIMStruct();
- dentry = get_dentry(w, path);
+ dentry = get_dentry(wim, path);
if (!dentry)
return -errno;
if (dentry_has_children(dentry))
return -ENOTEMPTY;
- remove_dentry(dentry, w->lookup_table);
+ remove_dentry(dentry, wim->lookup_table);
return 0;
}
{
struct wim_dentry *dentry;
struct wim_inode *inode;
- WIMStruct *w = wimfs_get_WIMStruct();
+ WIMStruct *wim = wimfs_get_WIMStruct();
- dentry = get_dentry(w, path);
+ dentry = get_dentry(wim, path);
if (!dentry)
return -errno;
inode = dentry->d_inode;
{
struct wim_dentry *dentry;
struct wim_inode *inode;
- WIMStruct *w = wimfs_get_WIMStruct();
+ WIMStruct *wim = wimfs_get_WIMStruct();
- dentry = get_dentry(w, path);
+ dentry = get_dentry(wim, path);
if (!dentry)
return -errno;
inode = dentry->d_inode;
* @ni: The NTFS inode to apply the metadata to.
* @dir_ni: The NTFS inode for a directory containing @ni.
* @dentry: The WIM dentry whose inode contains the metadata to apply.
- * @w: The WIMStruct for the WIM, through which the table of security
+ * @wim: The WIMStruct for the WIM, through which the table of security
* descriptors can be accessed.
*
* Returns 0 on success, nonzero on failure.
apply_file_attributes_and_security_data(ntfs_inode *ni,
ntfs_inode *dir_ni,
struct wim_dentry *dentry,
- const WIMStruct *w,
+ const WIMStruct *wim,
int extract_flags)
{
int ret;
const char *desc;
const struct wim_security_data *sd;
- sd = wim_const_security_data(w);
+ sd = wim_const_security_data(wim);
wimlib_assert(inode->i_security_id < sd->num_entries);
desc = (const char *)sd->descriptors[inode->i_security_id];
DEBUG("Applying security descriptor %d to `%s'",
}
ret = apply_file_attributes_and_security_data(ni, dir_ni, dentry,
- args->w,
+ args->wim,
args->extract_flags);
if (ret)
goto out_close_dir_ni;
static int
apply_root_dentry_ntfs(struct wim_dentry *dentry,
- ntfs_volume *vol, const WIMStruct *w,
+ ntfs_volume *vol, const WIMStruct *wim,
int extract_flags)
{
ntfs_inode *ni;
ERROR_WITH_ERRNO("Could not find root NTFS inode");
return WIMLIB_ERR_NTFS_3G;
}
- ret = apply_file_attributes_and_security_data(ni, ni, dentry, w,
+ ret = apply_file_attributes_and_security_data(ni, ni, dentry, wim,
extract_flags);
if (ntfs_inode_close(ni) != 0) {
ERROR_WITH_ERRNO("Failed to close NTFS inode for root "
{
struct apply_args *args = arg;
ntfs_volume *vol = args->vol;
- WIMStruct *w = args->w;
+ WIMStruct *wim = args->wim;
struct wim_dentry *orig_dentry;
struct wim_dentry *other;
int ret;
/* Treat the root dentry specially. */
if (dentry_is_root(dentry))
- return apply_root_dentry_ntfs(dentry, vol, w,
+ return apply_root_dentry_ntfs(dentry, vol, wim,
args->extract_flags);
/* NTFS filename namespaces need careful consideration. A name for a
/*
* merge_lookup_tables() - Merge lookup tables from the parts of a split WIM.
*
- * @w specifies the first part, while @additional_swms and @num_additional_swms
+ * @wim specifies the first part, while @additional_swms and @num_additional_swms
* specify an array of pointers to the WIMStruct's for additional split WIM parts.
*
* The reason we join the lookup tables is so we only have to search one lookup
* table to find the location of a resource in the entire WIM.
*/
void
-merge_lookup_tables(WIMStruct *w,
+merge_lookup_tables(WIMStruct *wim,
WIMStruct **additional_swms,
unsigned num_additional_swms)
{
for (unsigned i = 0; i < num_additional_swms; i++)
- lookup_table_join(w->lookup_table, additional_swms[i]->lookup_table);
+ lookup_table_join(wim->lookup_table, additional_swms[i]->lookup_table);
}
static int
* verify_swm_set: - Sanity checks to make sure a set of WIMs correctly
* correspond to a spanned set.
*
- * @w:
+ * @wim:
* Part 1 of the set.
*
* @additional_swms:
* 0 on success; WIMLIB_ERR_SPLIT_INVALID if the set is not valid.
*/
int
-verify_swm_set(WIMStruct *w, WIMStruct **additional_swms,
+verify_swm_set(WIMStruct *wim, WIMStruct **additional_swms,
unsigned num_additional_swms)
{
- unsigned total_parts = w->hdr.total_parts;
+ unsigned total_parts = wim->hdr.total_parts;
int ctype;
const u8 *guid;
if (total_parts != num_additional_swms + 1) {
ERROR("`%"TS"' says there are %u parts in the spanned set, "
"but %"TS"%u part%"TS" provided",
- w->filename, total_parts,
+ wim->filename, total_parts,
(num_additional_swms + 1 < total_parts) ? T("only ") : T(""),
num_additional_swms + 1,
(num_additional_swms) ? T("s were") : T(" was"));
return WIMLIB_ERR_SPLIT_INVALID;
}
- if (w->hdr.part_number != 1) {
+ if (wim->hdr.part_number != 1) {
ERROR("WIM `%"TS"' is not the first part of the split WIM.",
- w->filename);
+ wim->filename);
return WIMLIB_ERR_SPLIT_INVALID;
}
for (unsigned i = 0; i < num_additional_swms; i++) {
/* keep track of ctype and guid just to make sure they are the same for
* all the WIMs. */
- ctype = w->compression_type;
- guid = w->hdr.guid;
+ ctype = wim->compression_type;
+ guid = wim->hdr.guid;
{
/* parts_to_swms is not allocated at function scope because it
* should only be allocated after num_additional_swms was
- * checked to be the same as w->hdr.total_parts. Otherwise, it
+ * checked to be the same as wim->hdr.total_parts. Otherwise, it
* could be unexpectedly high and cause a stack overflow. */
WIMStruct *parts_to_swms[num_additional_swms];
ZERO_ARRAY(parts_to_swms);
if (swm->hdr.part_number == 1) {
ERROR("WIMs `%"TS"' and `%"TS"' both are marked "
"as the first WIM in the spanned set",
- w->filename, swm->filename);
+ wim->filename, swm->filename);
return WIMLIB_ERR_SPLIT_INVALID;
}
if (swm->hdr.part_number == 0 ||
#include <unistd.h>
static int
-image_print_metadata(WIMStruct *w)
+image_print_metadata(WIMStruct *wim)
{
- DEBUG("Printing metadata for image %d", w->current_image);
- print_wim_security_data(wim_security_data(w));
- return for_dentry_in_tree(wim_root_dentry(w), print_dentry,
- w->lookup_table);
+ DEBUG("Printing metadata for image %d", wim->current_image);
+ print_wim_security_data(wim_security_data(wim));
+ return for_dentry_in_tree(wim_root_dentry(wim), print_dentry,
+ wim->lookup_table);
}
static int
-image_print_files(WIMStruct *w)
+image_print_files(WIMStruct *wim)
{
- return for_dentry_in_tree(wim_root_dentry(w), print_dentry_full_path,
+ return for_dentry_in_tree(wim_root_dentry(wim), print_dentry_full_path,
NULL);
}
static WIMStruct *
new_wim_struct(void)
{
- WIMStruct *w = CALLOC(1, sizeof(WIMStruct));
- if (w) {
- w->in_fd = -1;
- w->out_fd = -1;
+ WIMStruct *wim = CALLOC(1, sizeof(WIMStruct));
+ if (wim) {
+ wim->in_fd = -1;
+ wim->out_fd = -1;
}
- return w;
+ return wim;
}
/*
* the WIM only once, with that image selected.
*/
int
-for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *))
+for_image(WIMStruct *wim, int image, int (*visitor)(WIMStruct *))
{
int ret;
int start;
if (image == WIMLIB_ALL_IMAGES) {
start = 1;
- end = w->hdr.image_count;
- } else if (image >= 1 && image <= w->hdr.image_count) {
+ end = wim->hdr.image_count;
+ } else if (image >= 1 && image <= wim->hdr.image_count) {
start = image;
end = image;
} else {
return WIMLIB_ERR_INVALID_IMAGE;
}
for (i = start; i <= end; i++) {
- ret = select_wim_image(w, i);
+ ret = select_wim_image(wim, i);
if (ret != 0)
return ret;
- ret = visitor(w);
+ ret = visitor(wim);
if (ret != 0)
return ret;
}
* Creates a WIMStruct for a new WIM file.
*/
WIMLIBAPI int
-wimlib_create_new_wim(int ctype, WIMStruct **w_ret)
+wimlib_create_new_wim(int ctype, WIMStruct **wim_ret)
{
- WIMStruct *w;
+ WIMStruct *wim;
struct wim_lookup_table *table;
int ret;
wimlib_get_compression_type_string(ctype));
/* Allocate the WIMStruct. */
- w = new_wim_struct();
- if (!w)
+ wim = new_wim_struct();
+ if (!wim)
return WIMLIB_ERR_NOMEM;
- ret = init_header(&w->hdr, ctype);
+ ret = init_header(&wim->hdr, ctype);
if (ret != 0)
goto out_free;
ret = WIMLIB_ERR_NOMEM;
goto out_free;
}
- w->lookup_table = table;
- w->refcnts_ok = 1;
- w->compression_type = ctype;
- *w_ret = w;
+ wim->lookup_table = table;
+ wim->refcnts_ok = 1;
+ wim->compression_type = ctype;
+ *wim_ret = wim;
return 0;
out_free:
- FREE(w);
+ FREE(wim);
return ret;
}
int
-select_wim_image(WIMStruct *w, int image)
+select_wim_image(WIMStruct *wim, int image)
{
struct wim_image_metadata *imd;
int ret;
return WIMLIB_ERR_INVALID_IMAGE;
}
- if (image == w->current_image)
+ if (image == wim->current_image)
return 0;
- if (image < 1 || image > w->hdr.image_count) {
+ if (image < 1 || image > wim->hdr.image_count) {
ERROR("Cannot select image %d: There are only %u images",
- image, w->hdr.image_count);
+ image, wim->hdr.image_count);
return WIMLIB_ERR_INVALID_IMAGE;
}
- if (w->hdr.part_number != 1) {
+ if (wim->hdr.part_number != 1) {
ERROR("Cannot select an image from a non-first part of a split WIM");
return WIMLIB_ERR_SPLIT_UNSUPPORTED;
}
/* If a valid image is currently selected, it can be freed if it is not
* modified. */
- if (w->current_image != WIMLIB_NO_IMAGE) {
- imd = wim_get_current_image_metadata(w);
+ if (wim->current_image != WIMLIB_NO_IMAGE) {
+ imd = wim_get_current_image_metadata(wim);
if (!imd->modified) {
wimlib_assert(list_empty(&imd->unhashed_streams));
- DEBUG("Freeing image %u", w->current_image);
+ DEBUG("Freeing image %u", wim->current_image);
destroy_image_metadata(imd, NULL, false);
}
}
- w->current_image = image;
- imd = wim_get_current_image_metadata(w);
+ wim->current_image = image;
+ imd = wim_get_current_image_metadata(wim);
if (imd->root_dentry || imd->modified) {
ret = 0;
} else {
"lookup table entry:");
print_lookup_table_entry(imd->metadata_lte, stderr);
#endif
- ret = read_metadata_resource(w, imd);
+ ret = read_metadata_resource(wim, imd);
if (ret)
- w->current_image = WIMLIB_NO_IMAGE;
+ wim->current_image = WIMLIB_NO_IMAGE;
}
return ret;
}
* starting at 1.
*/
WIMLIBAPI int
-wimlib_resolve_image(WIMStruct *w, const tchar *image_name_or_num)
+wimlib_resolve_image(WIMStruct *wim, const tchar *image_name_or_num)
{
tchar *p;
long image;
return WIMLIB_ALL_IMAGES;
image = tstrtol(image_name_or_num, &p, 10);
if (p != image_name_or_num && *p == T('\0') && image > 0) {
- if (image > w->hdr.image_count)
+ if (image > wim->hdr.image_count)
return WIMLIB_NO_IMAGE;
return image;
} else {
- for (i = 1; i <= w->hdr.image_count; i++) {
+ for (i = 1; i <= wim->hdr.image_count; i++) {
if (!tstrcmp(image_name_or_num,
- wimlib_get_image_name(w, i)))
+ wimlib_get_image_name(wim, i)))
return i;
}
return WIMLIB_NO_IMAGE;
}
WIMLIBAPI void
-wimlib_print_available_images(const WIMStruct *w, int image)
+wimlib_print_available_images(const WIMStruct *wim, int image)
{
int first;
int last;
if (image == WIMLIB_ALL_IMAGES) {
n = tprintf(T("Available Images:\n"));
first = 1;
- last = w->hdr.image_count;
- } else if (image >= 1 && image <= w->hdr.image_count) {
+ last = wim->hdr.image_count;
+ } else if (image >= 1 && image <= wim->hdr.image_count) {
n = tprintf(T("Information for Image %d\n"), image);
first = image;
last = image;
tputchar(T('-'));
tputchar(T('\n'));
for (i = first; i <= last; i++)
- print_image_info(w->wim_info, i);
+ print_image_info(wim->wim_info, i);
}
/* Prints the metadata for the specified image, which may be WIMLIB_ALL_IMAGES, but
* not WIMLIB_NO_IMAGE. */
WIMLIBAPI int
-wimlib_print_metadata(WIMStruct *w, int image)
+wimlib_print_metadata(WIMStruct *wim, int image)
{
- if (w->hdr.part_number != 1) {
+ if (wim->hdr.part_number != 1) {
ERROR("Cannot show the metadata from part %hu of a %hu-part split WIM!",
- w->hdr.part_number, w->hdr.total_parts);
+ wim->hdr.part_number, wim->hdr.total_parts);
ERROR("Select the first part of the split WIM to see the metadata.");
return WIMLIB_ERR_SPLIT_UNSUPPORTED;
}
- return for_image(w, image, image_print_metadata);
+ return for_image(wim, image, image_print_metadata);
}
WIMLIBAPI int
-wimlib_print_files(WIMStruct *w, int image)
+wimlib_print_files(WIMStruct *wim, int image)
{
- if (w->hdr.part_number != 1) {
+ if (wim->hdr.part_number != 1) {
ERROR("Cannot list the files from part %hu of a %hu-part split WIM!",
- w->hdr.part_number, w->hdr.total_parts);
+ wim->hdr.part_number, wim->hdr.total_parts);
ERROR("Select the first part of the split WIM if you'd like to list the files.");
return WIMLIB_ERR_SPLIT_UNSUPPORTED;
}
- return for_image(w, image, image_print_files);
+ return for_image(wim, image, image_print_files);
}
WIMLIBAPI int
}
int
-reopen_wim(WIMStruct *w)
+reopen_wim(WIMStruct *wim)
{
- wimlib_assert(w->in_fd == -1);
- return do_open_wim(w->filename, &w->in_fd);
+ wimlib_assert(wim->in_fd == -1);
+ return do_open_wim(wim->filename, &wim->in_fd);
}
int
-close_wim(WIMStruct *w)
+close_wim(WIMStruct *wim)
{
- if (w->in_fd != -1) {
- close(w->in_fd);
- w->in_fd = -1;
+ if (wim->in_fd != -1) {
+ close(wim->in_fd);
+ wim->in_fd = -1;
}
return 0;
}
* lookup table, and optionally checks the integrity.
*/
static int
-begin_read(WIMStruct *w, const tchar *in_wim_path, int open_flags,
+begin_read(WIMStruct *wim, const tchar *in_wim_path, int open_flags,
wimlib_progress_func_t progress_func)
{
int ret;
DEBUG("Reading the WIM file `%"TS"'", in_wim_path);
- ret = do_open_wim(in_wim_path, &w->in_fd);
+ ret = do_open_wim(in_wim_path, &wim->in_fd);
if (ret)
return ret;
* Warning: in Windows native builds, realpath() calls the replacement
* function in win32.c.
*/
- w->filename = realpath(in_wim_path, NULL);
- if (!w->filename) {
+ wim->filename = realpath(in_wim_path, NULL);
+ if (!wim->filename) {
ERROR_WITH_ERRNO("Failed to resolve WIM filename");
if (errno == ENOMEM)
return WIMLIB_ERR_NOMEM;
return WIMLIB_ERR_OPEN;
}
- ret = read_header(w->filename, w->in_fd, &w->hdr);
+ ret = read_header(wim->filename, wim->in_fd, &wim->hdr);
if (ret)
return ret;
- if (w->hdr.flags & WIM_HDR_FLAG_WRITE_IN_PROGRESS) {
+ if (wim->hdr.flags & WIM_HDR_FLAG_WRITE_IN_PROGRESS) {
WARNING("The WIM_HDR_FLAG_WRITE_IN_PROGRESS is set in the header of \"%"TS"\".\n"
" It may be being changed by another process, or a process\n"
" may have crashed while writing the WIM.", in_wim_path);
}
if (open_flags & WIMLIB_OPEN_FLAG_WRITE_ACCESS) {
- ret = can_modify_wim(w);
+ ret = can_modify_wim(wim);
if (ret)
return ret;
}
- if (w->hdr.total_parts != 1 && !(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK)) {
+ if (wim->hdr.total_parts != 1 && !(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK)) {
ERROR("\"%"TS"\": This WIM is part %u of a %u-part WIM",
- in_wim_path, w->hdr.part_number, w->hdr.total_parts);
+ in_wim_path, wim->hdr.part_number, wim->hdr.total_parts);
return WIMLIB_ERR_SPLIT_UNSUPPORTED;
}
- DEBUG("According to header, WIM contains %u images", w->hdr.image_count);
+ DEBUG("According to header, WIM contains %u images", wim->hdr.image_count);
/* If the boot index is invalid, print a warning and set it to 0 */
- if (w->hdr.boot_idx > w->hdr.image_count) {
+ if (wim->hdr.boot_idx > wim->hdr.image_count) {
WARNING("In `%"TS"', image %u is marked as bootable, "
"but there are only %u images in the WIM",
- in_wim_path, w->hdr.boot_idx, w->hdr.image_count);
- w->hdr.boot_idx = 0;
+ in_wim_path, wim->hdr.boot_idx, wim->hdr.image_count);
+ wim->hdr.boot_idx = 0;
}
/* Check and cache the compression type */
- if (w->hdr.flags & WIM_HDR_FLAG_COMPRESSION) {
- if (w->hdr.flags & WIM_HDR_FLAG_COMPRESS_LZX) {
- if (w->hdr.flags & WIM_HDR_FLAG_COMPRESS_XPRESS) {
+ if (wim->hdr.flags & WIM_HDR_FLAG_COMPRESSION) {
+ if (wim->hdr.flags & WIM_HDR_FLAG_COMPRESS_LZX) {
+ if (wim->hdr.flags & WIM_HDR_FLAG_COMPRESS_XPRESS) {
ERROR("Multiple compression flags are set in \"%"TS"\"",
in_wim_path);
return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
}
- w->compression_type = WIMLIB_COMPRESSION_TYPE_LZX;
- } else if (w->hdr.flags & WIM_HDR_FLAG_COMPRESS_XPRESS) {
- w->compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS;
+ wim->compression_type = WIMLIB_COMPRESSION_TYPE_LZX;
+ } else if (wim->hdr.flags & WIM_HDR_FLAG_COMPRESS_XPRESS) {
+ wim->compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS;
} else {
ERROR("The compression flag is set on \"%"TS"\", but "
"neither the XPRESS nor LZX flag is set",
}
if (open_flags & WIMLIB_OPEN_FLAG_CHECK_INTEGRITY) {
- ret = check_wim_integrity(w, progress_func);
+ ret = check_wim_integrity(wim, progress_func);
if (ret == WIM_INTEGRITY_NONEXISTENT) {
WARNING("No integrity information for `%"TS"'; skipping "
"integrity check.", in_wim_path);
}
}
- if (w->hdr.image_count != 0 && w->hdr.part_number == 1) {
- w->image_metadata = new_image_metadata_array(w->hdr.image_count);
- if (!w->image_metadata)
+ if (wim->hdr.image_count != 0 && wim->hdr.part_number == 1) {
+ wim->image_metadata = new_image_metadata_array(wim->hdr.image_count);
+ if (!wim->image_metadata)
return WIMLIB_ERR_NOMEM;
}
- ret = read_lookup_table(w);
+ ret = read_lookup_table(wim);
if (ret)
return ret;
- ret = read_xml_data(w->in_fd, &w->hdr.xml_res_entry, &w->wim_info);
+ ret = read_xml_data(wim->in_fd, &wim->hdr.xml_res_entry, &wim->wim_info);
if (ret)
return ret;
- xml_num_images = wim_info_get_num_images(w->wim_info);
- if (xml_num_images != w->hdr.image_count) {
+ xml_num_images = wim_info_get_num_images(wim->wim_info);
+ if (xml_num_images != wim->hdr.image_count) {
ERROR("In the file `%"TS"', there are %u <IMAGE> elements "
"in the XML data,", in_wim_path, xml_num_images);
ERROR("but %u images in the WIM! There must be exactly one "
- "<IMAGE> element per image.", w->hdr.image_count);
+ "<IMAGE> element per image.", wim->hdr.image_count);
return WIMLIB_ERR_IMAGE_COUNT;
}
/* Appends the specified image metadata structure to the array of image metadata
* for a WIM, and increments the image count. */
int
-append_image_metadata(WIMStruct *w, struct wim_image_metadata *imd)
+append_image_metadata(WIMStruct *wim, struct wim_image_metadata *imd)
{
struct wim_image_metadata **imd_array;
DEBUG("Reallocating image metadata array for image_count = %u",
- w->hdr.image_count + 1);
- imd_array = REALLOC(w->image_metadata,
- sizeof(w->image_metadata[0]) * (w->hdr.image_count + 1));
+ wim->hdr.image_count + 1);
+ imd_array = REALLOC(wim->image_metadata,
+ sizeof(wim->image_metadata[0]) * (wim->hdr.image_count + 1));
if (!imd_array)
return WIMLIB_ERR_NOMEM;
- w->image_metadata = imd_array;
- imd_array[w->hdr.image_count++] = imd;
+ wim->image_metadata = imd_array;
+ imd_array[wim->hdr.image_count++] = imd;
return 0;
}
* library has previously used to add or mount an image using the same
* WIMStruct. */
int
-wim_checksum_unhashed_streams(WIMStruct *w)
+wim_checksum_unhashed_streams(WIMStruct *wim)
{
int ret;
- for (int i = 0; i < w->hdr.image_count; i++) {
+ for (int i = 0; i < wim->hdr.image_count; i++) {
struct wim_lookup_table_entry *lte, *tmp;
- struct wim_image_metadata *imd = w->image_metadata[i];
+ struct wim_image_metadata *imd = wim->image_metadata[i];
image_for_each_unhashed_stream_safe(lte, tmp, imd) {
- ret = hash_unhashed_stream(lte, w->lookup_table, NULL);
+ ret = hash_unhashed_stream(lte, wim->lookup_table, NULL);
if (ret)
return ret;
}
/* Frees the memory for the WIMStruct, including all internal memory; also
* closes all files associated with the WIMStruct. */
WIMLIBAPI void
-wimlib_free(WIMStruct *w)
+wimlib_free(WIMStruct *wim)
{
DEBUG("Freeing WIMStruct");
- if (!w)
+ if (!wim)
return;
- if (w->in_fd != -1)
- close(w->in_fd);
- if (w->out_fd != -1)
- close(w->out_fd);
+ if (wim->in_fd != -1)
+ close(wim->in_fd);
+ if (wim->out_fd != -1)
+ close(wim->out_fd);
- free_lookup_table(w->lookup_table);
+ free_lookup_table(wim->lookup_table);
- FREE(w->filename);
- free_wim_info(w->wim_info);
- if (w->image_metadata) {
- for (unsigned i = 0; i < w->hdr.image_count; i++)
- put_image_metadata(w->image_metadata[i], NULL);
- FREE(w->image_metadata);
+ FREE(wim->filename);
+ free_wim_info(wim->wim_info);
+ if (wim->image_metadata) {
+ for (unsigned i = 0; i < wim->hdr.image_count; i++)
+ put_image_metadata(wim->image_metadata[i], NULL);
+ FREE(wim->image_metadata);
}
- FREE(w);
+ FREE(wim);
DEBUG("Freed WIMStruct");
}
}
static int
-image_find_streams_to_write(WIMStruct *w)
+image_find_streams_to_write(WIMStruct *wim)
{
struct find_streams_ctx *ctx;
struct wim_image_metadata *imd;
struct wim_inode *inode;
struct wim_lookup_table_entry *lte;
- ctx = w->private;
- imd = wim_get_current_image_metadata(w);
+ ctx = wim->private;
+ imd = wim_get_current_image_metadata(wim);
image_for_each_unhashed_stream(lte, imd)
lte->out_refcnt = 0;
/* Go through this image's inodes to find any streams that have not been
* found yet. */
image_for_each_inode(inode, imd) {
- inode_find_streams_to_write(inode, w->lookup_table,
+ inode_find_streams_to_write(inode, wim->lookup_table,
&ctx->stream_list,
&ctx->stream_size_tab);
}
*
*/
int
-finish_write(WIMStruct *w, int image, int write_flags,
+finish_write(WIMStruct *wim, int image, int write_flags,
wimlib_progress_func_t progress_func)
{
int ret;
* from the header in the WIMStruct; then set all the fields that may
* have changed, including the resource entries, boot index, and image
* count. */
- memcpy(&hdr, &w->hdr, sizeof(struct wim_header));
+ memcpy(&hdr, &wim->hdr, sizeof(struct wim_header));
/* Set image count and boot index correctly for single image writes */
if (image != WIMLIB_ALL_IMAGES) {
zero_resource_entry(&hdr.boot_metadata_res_entry);
} else {
copy_resource_entry(&hdr.boot_metadata_res_entry,
- &w->image_metadata[ hdr.boot_idx- 1
+ &wim->image_metadata[ hdr.boot_idx- 1
]->metadata_lte->output_resource_entry);
}
if (!(write_flags & WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE)) {
- ret = write_lookup_table(w, image, &hdr.lookup_table_res_entry);
+ ret = write_lookup_table(wim, image, &hdr.lookup_table_res_entry);
if (ret)
goto out_close_wim;
}
- ret = write_xml_data(w->wim_info, image, w->out_fd,
+ ret = write_xml_data(wim->wim_info, image, wim->out_fd,
(write_flags & WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE) ?
- wim_info_get_total_bytes(w->wim_info) : 0,
+ wim_info_get_total_bytes(wim->wim_info) : 0,
&hdr.xml_res_entry);
if (ret)
goto out_close_wim;
memcpy(&checkpoint_hdr, &hdr, sizeof(struct wim_header));
zero_resource_entry(&checkpoint_hdr.integrity);
checkpoint_hdr.flags |= WIM_HDR_FLAG_WRITE_IN_PROGRESS;
- ret = write_header(&checkpoint_hdr, w->out_fd);
+ ret = write_header(&checkpoint_hdr, wim->out_fd);
if (ret)
goto out_close_wim;
}
off_t old_lookup_table_end;
off_t new_lookup_table_end;
if (write_flags & WIMLIB_WRITE_FLAG_REUSE_INTEGRITY_TABLE) {
- old_lookup_table_end = w->hdr.lookup_table_res_entry.offset +
- w->hdr.lookup_table_res_entry.size;
+ old_lookup_table_end = wim->hdr.lookup_table_res_entry.offset +
+ wim->hdr.lookup_table_res_entry.size;
} else {
old_lookup_table_end = 0;
}
new_lookup_table_end = hdr.lookup_table_res_entry.offset +
hdr.lookup_table_res_entry.size;
- ret = write_integrity_table(w->out_fd,
+ ret = write_integrity_table(wim->out_fd,
&hdr.integrity,
new_lookup_table_end,
old_lookup_table_end,
}
hdr.flags &= ~WIM_HDR_FLAG_WRITE_IN_PROGRESS;
- ret = write_header(&hdr, w->out_fd);
+ ret = write_header(&hdr, wim->out_fd);
if (ret)
goto out_close_wim;
if (write_flags & WIMLIB_WRITE_FLAG_FSYNC) {
- if (fsync(w->out_fd)) {
+ if (fsync(wim->out_fd)) {
ERROR_WITH_ERRNO("Error syncing data to WIM file");
ret = WIMLIB_ERR_WRITE;
}
}
out_close_wim:
- if (close(w->out_fd)) {
+ if (close(wim->out_fd)) {
ERROR_WITH_ERRNO("Failed to close the output WIM file");
if (ret == 0)
ret = WIMLIB_ERR_WRITE;
}
- w->out_fd = -1;
+ wim->out_fd = -1;
return ret;
}
#if defined(HAVE_SYS_FILE_H) && defined(HAVE_FLOCK)
int
-lock_wim(WIMStruct *w, int fd)
+lock_wim(WIMStruct *wim, int fd)
{
int ret = 0;
- if (fd != -1 && !w->wim_locked) {
+ if (fd != -1 && !wim->wim_locked) {
ret = flock(fd, LOCK_EX | LOCK_NB);
if (ret != 0) {
if (errno == EWOULDBLOCK) {
ERROR("`%"TS"' is already being modified or has been "
"mounted read-write\n"
- " by another process!", w->filename);
+ " by another process!", wim->filename);
ret = WIMLIB_ERR_ALREADY_LOCKED;
} else {
WARNING_WITH_ERRNO("Failed to lock `%"TS"'",
- w->filename);
+ wim->filename);
ret = 0;
}
} else {
- w->wim_locked = 1;
+ wim->wim_locked = 1;
}
}
return ret;
#endif
static int
-open_wim_writable(WIMStruct *w, const tchar *path, int open_flags)
+open_wim_writable(WIMStruct *wim, const tchar *path, int open_flags)
{
- w->out_fd = topen(path, open_flags | O_BINARY, 0644);
- if (w->out_fd == -1) {
+ wim->out_fd = topen(path, open_flags | O_BINARY, 0644);
+ if (wim->out_fd == -1) {
ERROR_WITH_ERRNO("Failed to open `%"TS"' for writing", path);
return WIMLIB_ERR_OPEN;
}
void
-close_wim_writable(WIMStruct *w)
+close_wim_writable(WIMStruct *wim)
{
- if (w->out_fd != -1) {
- if (close(w->out_fd))
+ if (wim->out_fd != -1) {
+ if (close(wim->out_fd))
WARNING_WITH_ERRNO("Failed to close output WIM");
- w->out_fd = -1;
+ wim->out_fd = -1;
}
}
/* Open file stream and write dummy header for WIM. */
int
-begin_write(WIMStruct *w, const tchar *path, int write_flags)
+begin_write(WIMStruct *wim, const tchar *path, int write_flags)
{
int ret;
int open_flags = O_TRUNC | O_CREAT;
open_flags |= O_RDWR;
else
open_flags |= O_WRONLY;
- ret = open_wim_writable(w, path, open_flags);
+ ret = open_wim_writable(wim, path, open_flags);
if (ret)
return ret;
/* Write dummy header. It will be overwritten later. */
- w->hdr.flags |= WIM_HDR_FLAG_WRITE_IN_PROGRESS;
- ret = write_header(&w->hdr, w->out_fd);
- w->hdr.flags &= ~WIM_HDR_FLAG_WRITE_IN_PROGRESS;
+ wim->hdr.flags |= WIM_HDR_FLAG_WRITE_IN_PROGRESS;
+ ret = write_header(&wim->hdr, wim->out_fd);
+ wim->hdr.flags &= ~WIM_HDR_FLAG_WRITE_IN_PROGRESS;
if (ret)
return ret;
- if (lseek(w->out_fd, WIM_HEADER_DISK_SIZE, SEEK_SET) == -1) {
+ if (lseek(wim->out_fd, WIM_HEADER_DISK_SIZE, SEEK_SET) == -1) {
ERROR_WITH_ERRNO("Failed to seek to end of WIM header");
return WIMLIB_ERR_WRITE;
}
/* Writes a stand-alone WIM to a file. */
WIMLIBAPI int
-wimlib_write(WIMStruct *w, const tchar *path,
+wimlib_write(WIMStruct *wim, const tchar *path,
int image, int write_flags, unsigned num_threads,
wimlib_progress_func_t progress_func)
{
write_flags &= WIMLIB_WRITE_MASK_PUBLIC;
if (image != WIMLIB_ALL_IMAGES &&
- (image < 1 || image > w->hdr.image_count))
+ (image < 1 || image > wim->hdr.image_count))
return WIMLIB_ERR_INVALID_IMAGE;
- if (w->hdr.total_parts != 1) {
+ if (wim->hdr.total_parts != 1) {
ERROR("Cannot call wimlib_write() on part of a split WIM");
return WIMLIB_ERR_SPLIT_UNSUPPORTED;
}
- ret = begin_write(w, path, write_flags);
+ ret = begin_write(wim, path, write_flags);
if (ret)
goto out_close_wim;
- ret = write_wim_streams(w, image, write_flags, num_threads,
+ ret = write_wim_streams(wim, image, write_flags, num_threads,
progress_func);
if (ret)
goto out_close_wim;
if (progress_func)
progress_func(WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN, NULL);
- ret = for_image(w, image, write_metadata_resource);
+ ret = for_image(wim, image, write_metadata_resource);
if (ret)
goto out_close_wim;
if (progress_func)
progress_func(WIMLIB_PROGRESS_MSG_WRITE_METADATA_END, NULL);
- ret = finish_write(w, image, write_flags, progress_func);
+ ret = finish_write(wim, image, write_flags, progress_func);
/* finish_write() closed the WIM for us */
goto out;
out_close_wim:
- close_wim_writable(w);
+ close_wim_writable(wim);
out:
DEBUG("wimlib_write(path=%"TS") = %d", path, ret);
return ret;
}
static bool
-any_images_modified(WIMStruct *w)
+any_images_modified(WIMStruct *wim)
{
- for (int i = 0; i < w->hdr.image_count; i++)
- if (w->image_metadata[i]->modified)
+ for (int i = 0; i < wim->hdr.image_count; i++)
+ if (wim->image_metadata[i]->modified)
return true;
return false;
}
* small amount of space compared to the streams, however.)
*/
static int
-overwrite_wim_inplace(WIMStruct *w, int write_flags,
+overwrite_wim_inplace(WIMStruct *wim, int write_flags,
unsigned num_threads,
wimlib_progress_func_t progress_func)
{
u64 old_lookup_table_end, old_xml_begin, old_xml_end;
int open_flags;
- DEBUG("Overwriting `%"TS"' in-place", w->filename);
+ DEBUG("Overwriting `%"TS"' in-place", wim->filename);
/* Make sure that the integrity table (if present) is after the XML
* data, and that there are no stream resources, metadata resources, or
* lookup tables after the XML data. Otherwise, these data would be
* overwritten. */
- old_xml_begin = w->hdr.xml_res_entry.offset;
- old_xml_end = old_xml_begin + w->hdr.xml_res_entry.size;
- old_lookup_table_end = w->hdr.lookup_table_res_entry.offset +
- w->hdr.lookup_table_res_entry.size;
- if (w->hdr.integrity.offset != 0 && w->hdr.integrity.offset < old_xml_end) {
+ old_xml_begin = wim->hdr.xml_res_entry.offset;
+ old_xml_end = old_xml_begin + wim->hdr.xml_res_entry.size;
+ old_lookup_table_end = wim->hdr.lookup_table_res_entry.offset +
+ wim->hdr.lookup_table_res_entry.size;
+ if (wim->hdr.integrity.offset != 0 && wim->hdr.integrity.offset < old_xml_end) {
ERROR("Didn't expect the integrity table to be before the XML data");
return WIMLIB_ERR_RESOURCE_ORDER;
}
* allow any file and metadata resources to appear without returning
* WIMLIB_ERR_RESOURCE_ORDER (due to the fact that we would otherwise
* overwrite these resources). */
- if (!w->deletion_occurred && !any_images_modified(w)) {
+ if (!wim->deletion_occurred && !any_images_modified(wim)) {
/* If no images have been modified and no images have been
* deleted, a new lookup table does not need to be written. We
* shall write the new XML data and optional integrity table
old_wim_end = old_lookup_table_end;
write_flags |= WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE |
WIMLIB_WRITE_FLAG_CHECKPOINT_AFTER_XML;
- } else if (w->hdr.integrity.offset) {
+ } else if (wim->hdr.integrity.offset) {
/* Old WIM has an integrity table; begin writing new streams
* after it. */
- old_wim_end = w->hdr.integrity.offset + w->hdr.integrity.size;
+ old_wim_end = wim->hdr.integrity.offset + wim->hdr.integrity.size;
} else {
/* No existing integrity table; begin writing new streams after
* the old XML data. */
old_wim_end = old_xml_end;
}
- ret = prepare_streams_for_overwrite(w, old_wim_end, &stream_list);
+ ret = prepare_streams_for_overwrite(wim, old_wim_end, &stream_list);
if (ret)
return ret;
open_flags |= O_RDWR;
else
open_flags |= O_WRONLY;
- ret = open_wim_writable(w, w->filename, open_flags);
+ ret = open_wim_writable(wim, wim->filename, open_flags);
if (ret)
return ret;
- ret = lock_wim(w, w->out_fd);
+ ret = lock_wim(wim, wim->out_fd);
if (ret) {
- close_wim_writable(w);
+ close_wim_writable(wim);
return ret;
}
/* Set WIM_HDR_FLAG_WRITE_IN_PROGRESS flag in header. */
- ret = write_header_flags(w->hdr.flags | WIM_HDR_FLAG_WRITE_IN_PROGRESS,
- w->out_fd);
+ ret = write_header_flags(wim->hdr.flags | WIM_HDR_FLAG_WRITE_IN_PROGRESS,
+ wim->out_fd);
if (ret) {
ERROR_WITH_ERRNO("Error updating WIM header flags");
- close_wim_writable(w);
+ close_wim_writable(wim);
goto out_unlock_wim;
}
- if (lseek(w->out_fd, old_wim_end, SEEK_SET) == -1) {
+ if (lseek(wim->out_fd, old_wim_end, SEEK_SET) == -1) {
ERROR_WITH_ERRNO("Can't seek to end of WIM");
- close_wim_writable(w);
+ close_wim_writable(wim);
ret = WIMLIB_ERR_WRITE;
goto out_unlock_wim;
}
DEBUG("Writing newly added streams (offset = %"PRIu64")",
old_wim_end);
ret = write_stream_list(&stream_list,
- w->lookup_table,
- w->out_fd,
- w->compression_type,
+ wim->lookup_table,
+ wim->out_fd,
+ wim->compression_type,
write_flags,
num_threads,
progress_func);
if (ret)
goto out_truncate;
- for (int i = 0; i < w->hdr.image_count; i++) {
- if (w->image_metadata[i]->modified) {
- select_wim_image(w, i + 1);
- ret = write_metadata_resource(w);
+ for (int i = 0; i < wim->hdr.image_count; i++) {
+ if (wim->image_metadata[i]->modified) {
+ select_wim_image(wim, i + 1);
+ ret = write_metadata_resource(wim);
if (ret)
goto out_truncate;
}
}
write_flags |= WIMLIB_WRITE_FLAG_REUSE_INTEGRITY_TABLE;
- ret = finish_write(w, WIMLIB_ALL_IMAGES, write_flags,
+ ret = finish_write(wim, WIMLIB_ALL_IMAGES, write_flags,
progress_func);
out_truncate:
- close_wim_writable(w);
+ close_wim_writable(wim);
if (ret != 0 && !(write_flags & WIMLIB_WRITE_FLAG_NO_LOOKUP_TABLE)) {
WARNING("Truncating `%"TS"' to its original size (%"PRIu64" bytes)",
- w->filename, old_wim_end);
+ wim->filename, old_wim_end);
/* Return value of truncate() is ignored because this is already
* an error path. */
- (void)ttruncate(w->filename, old_wim_end);
+ (void)ttruncate(wim->filename, old_wim_end);
}
out_unlock_wim:
- w->wim_locked = 0;
+ wim->wim_locked = 0;
return ret;
}
static int
-overwrite_wim_via_tmpfile(WIMStruct *w, int write_flags,
+overwrite_wim_via_tmpfile(WIMStruct *wim, int write_flags,
unsigned num_threads,
wimlib_progress_func_t progress_func)
{
size_t wim_name_len;
int ret;
- DEBUG("Overwriting `%"TS"' via a temporary file", w->filename);
+ DEBUG("Overwriting `%"TS"' via a temporary file", wim->filename);
/* Write the WIM to a temporary file in the same directory as the
* original WIM. */
- wim_name_len = tstrlen(w->filename);
+ wim_name_len = tstrlen(wim->filename);
tchar tmpfile[wim_name_len + 10];
- tmemcpy(tmpfile, w->filename, wim_name_len);
+ tmemcpy(tmpfile, wim->filename, wim_name_len);
randomize_char_array_with_alnum(tmpfile + wim_name_len, 9);
tmpfile[wim_name_len + 9] = T('\0');
- ret = wimlib_write(w, tmpfile, WIMLIB_ALL_IMAGES,
+ ret = wimlib_write(wim, tmpfile, WIMLIB_ALL_IMAGES,
write_flags | WIMLIB_WRITE_FLAG_FSYNC,
num_threads, progress_func);
if (ret) {
goto out_unlink;
}
- close_wim(w);
+ close_wim(wim);
- DEBUG("Renaming `%"TS"' to `%"TS"'", tmpfile, w->filename);
+ DEBUG("Renaming `%"TS"' to `%"TS"'", tmpfile, wim->filename);
/* Rename the new file to the old file .*/
- if (trename(tmpfile, w->filename) != 0) {
+ if (trename(tmpfile, wim->filename) != 0) {
ERROR_WITH_ERRNO("Failed to rename `%"TS"' to `%"TS"'",
- tmpfile, w->filename);
+ tmpfile, wim->filename);
ret = WIMLIB_ERR_RENAME;
goto out_unlink;
}
if (progress_func) {
union wimlib_progress_info progress;
progress.rename.from = tmpfile;
- progress.rename.to = w->filename;
+ progress.rename.to = wim->filename;
progress_func(WIMLIB_PROGRESS_MSG_RENAME, &progress);
}
goto out;
* Writes a WIM file to the original file that it was read from, overwriting it.
*/
WIMLIBAPI int
-wimlib_overwrite(WIMStruct *w, int write_flags,
+wimlib_overwrite(WIMStruct *wim, int write_flags,
unsigned num_threads,
wimlib_progress_func_t progress_func)
{
write_flags &= WIMLIB_WRITE_MASK_PUBLIC;
- if (!w->filename)
+ if (!wim->filename)
return WIMLIB_ERR_NO_FILENAME;
- orig_hdr_flags = w->hdr.flags;
+ orig_hdr_flags = wim->hdr.flags;
if (write_flags & WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG)
- w->hdr.flags &= ~WIM_HDR_FLAG_READONLY;
- ret = can_modify_wim(w);
- w->hdr.flags = orig_hdr_flags;
+ wim->hdr.flags &= ~WIM_HDR_FLAG_READONLY;
+ ret = can_modify_wim(wim);
+ wim->hdr.flags = orig_hdr_flags;
if (ret)
return ret;
- if ((!w->deletion_occurred || (write_flags & WIMLIB_WRITE_FLAG_SOFT_DELETE))
+ if ((!wim->deletion_occurred || (write_flags & WIMLIB_WRITE_FLAG_SOFT_DELETE))
&& !(write_flags & WIMLIB_WRITE_FLAG_REBUILD))
{
int ret;
- ret = overwrite_wim_inplace(w, write_flags, num_threads,
+ ret = overwrite_wim_inplace(wim, write_flags, num_threads,
progress_func);
if (ret == WIMLIB_ERR_RESOURCE_ORDER)
WARNING("Falling back to re-building entire WIM");
else
return ret;
}
- return overwrite_wim_via_tmpfile(w, write_flags, num_threads,
+ return overwrite_wim_via_tmpfile(wim, write_flags, num_threads,
progress_func);
}
}
size_t
-xml_get_max_image_name_len(const WIMStruct *w)
+xml_get_max_image_name_len(const WIMStruct *wim)
{
size_t max_len = 0;
- if (w->wim_info) {
- for (int i = 0; i < w->wim_info->num_images; i++) {
- size_t len = tstrlen(w->wim_info->images[i].name);
+ if (wim->wim_info) {
+ for (int i = 0; i < wim->wim_info->num_images; i++) {
+ size_t len = tstrlen(wim->wim_info->images[i].name);
if (len > max_len)
max_len = len;
}
* But, see calculate_dentry_statistics().
*/
void
-xml_update_image_info(WIMStruct *w, int image)
+xml_update_image_info(WIMStruct *wim, int image)
{
struct image_info *image_info;
DEBUG("Updating the image info for image %d", image);
- image_info = &w->wim_info->images[image - 1];
+ image_info = &wim->wim_info->images[image - 1];
image_info->file_count = 0;
image_info->dir_count = 0;
image_info->total_bytes = 0;
image_info->hard_link_bytes = 0;
- image_info->lookup_table = w->lookup_table;
+ image_info->lookup_table = wim->lookup_table;
- for_dentry_in_tree(w->image_metadata[image - 1]->root_dentry,
+ for_dentry_in_tree(wim->image_metadata[image - 1]->root_dentry,
calculate_dentry_statistics,
image_info);
image_info->last_modification_time = get_wim_timestamp();
/* Adds an image to the XML information. */
int
-xml_add_image(WIMStruct *w, const tchar *name)
+xml_add_image(WIMStruct *wim, const tchar *name)
{
struct wim_info *wim_info;
struct image_info *image_info;
/* If this is the first image, allocate the struct wim_info. Otherwise
* use the existing struct wim_info. */
- if (w->wim_info) {
- wim_info = w->wim_info;
+ if (wim->wim_info) {
+ wim_info = wim->wim_info;
} else {
wim_info = CALLOC(1, sizeof(struct wim_info));
if (!wim_info)
if (!(image_info->name = TSTRDUP(name)))
goto out_destroy_image_info;
- w->wim_info = wim_info;
+ wim->wim_info = wim_info;
image_info->index = wim_info->num_images;
image_info->creation_time = get_wim_timestamp();
- xml_update_image_info(w, image_info->index);
+ xml_update_image_info(wim, image_info->index);
return 0;
out_destroy_image_info:
destroy_image_info(image_info);
wim_info->num_images--;
out_free_wim_info:
- if (wim_info != w->wim_info)
+ if (wim_info != wim->wim_info)
FREE(wim_info);
return WIMLIB_ERR_NOMEM;
}
/* Returns the name of the specified image. */
WIMLIBAPI const tchar *
-wimlib_get_image_name(const WIMStruct *w, int image)
+wimlib_get_image_name(const WIMStruct *wim, int image)
{
- if (image < 1 || image > w->hdr.image_count)
+ if (image < 1 || image > wim->hdr.image_count)
return NULL;
- return w->wim_info->images[image - 1].name;
+ return wim->wim_info->images[image - 1].name;
}
/* Returns the description of the specified image. */
WIMLIBAPI const tchar *
-wimlib_get_image_description(const WIMStruct *w, int image)
+wimlib_get_image_description(const WIMStruct *wim, int image)
{
- if (image < 1 || image > w->hdr.image_count)
+ if (image < 1 || image > wim->hdr.image_count)
return NULL;
- return w->wim_info->images[image - 1].description;
+ return wim->wim_info->images[image - 1].description;
}
/* Determines if an image name is already used by some image in the WIM. */
WIMLIBAPI bool
-wimlib_image_name_in_use(const WIMStruct *w, const tchar *name)
+wimlib_image_name_in_use(const WIMStruct *wim, const tchar *name)
{
if (!name || !*name)
return false;
- for (int i = 1; i <= w->hdr.image_count; i++)
- if (!tstrcmp(w->wim_info->images[i - 1].name, name))
+ for (int i = 1; i <= wim->hdr.image_count; i++)
+ if (!tstrcmp(wim->wim_info->images[i - 1].name, name))
return true;
return false;
}
/* Extracts the raw XML data to a file stream. */
WIMLIBAPI int
-wimlib_extract_xml_data(WIMStruct *w, FILE *fp)
+wimlib_extract_xml_data(WIMStruct *wim, FILE *fp)
{
size_t size;
void *buf;
int ret;
- size = w->hdr.xml_res_entry.size;
+ size = wim->hdr.xml_res_entry.size;
if (sizeof(size_t) < sizeof(u64))
- if (size != w->hdr.xml_res_entry.size)
+ if (size != wim->hdr.xml_res_entry.size)
return WIMLIB_ERR_INVALID_PARAM;
buf = MALLOC(size);
if (!buf)
return WIMLIB_ERR_NOMEM;
- if (full_pread(w->in_fd,
+ if (full_pread(wim->in_fd,
buf,
- w->hdr.xml_res_entry.size,
- w->hdr.xml_res_entry.offset) != w->hdr.xml_res_entry.size)
+ wim->hdr.xml_res_entry.size,
+ wim->hdr.xml_res_entry.offset) != wim->hdr.xml_res_entry.size)
{
ERROR_WITH_ERRNO("Error reading XML data");
ret = WIMLIB_ERR_READ;
/* Sets the name of an image in the WIM. */
WIMLIBAPI int
-wimlib_set_image_name(WIMStruct *w, int image, const tchar *name)
+wimlib_set_image_name(WIMStruct *wim, int image, const tchar *name)
{
tchar *p;
int i;
DEBUG("Setting the name of image %d to %"TS, image, name);
- ret = can_modify_wim(w);
+ ret = can_modify_wim(wim);
if (ret)
return ret;
if (name == NULL)
name = T("");
- if (image < 1 || image > w->hdr.image_count) {
+ if (image < 1 || image > wim->hdr.image_count) {
ERROR("%d is not a valid image", image);
return WIMLIB_ERR_INVALID_IMAGE;
}
- for (i = 1; i <= w->hdr.image_count; i++) {
+ for (i = 1; i <= wim->hdr.image_count; i++) {
if (i == image)
continue;
- if (!tstrcmp(w->wim_info->images[i - 1].name, name)) {
+ if (!tstrcmp(wim->wim_info->images[i - 1].name, name)) {
ERROR("The name \"%"TS"\" is already in use in the WIM!",
name);
return WIMLIB_ERR_IMAGE_NAME_COLLISION;
if (!p)
return WIMLIB_ERR_NOMEM;
- FREE(w->wim_info->images[image - 1].name);
- w->wim_info->images[image - 1].name = p;
+ FREE(wim->wim_info->images[image - 1].name);
+ wim->wim_info->images[image - 1].name = p;
return 0;
}
static int
-do_set_image_info_str(WIMStruct *w, int image, const tchar *tstr,
+do_set_image_info_str(WIMStruct *wim, int image, const tchar *tstr,
size_t offset)
{
tchar *tstr_copy;
tchar **dest_tstr_p;
int ret;
- ret = can_modify_wim(w);
+ ret = can_modify_wim(wim);
if (ret)
return ret;
- if (image < 1 || image > w->hdr.image_count) {
+ if (image < 1 || image > wim->hdr.image_count) {
ERROR("%d is not a valid image", image);
return WIMLIB_ERR_INVALID_IMAGE;
}
} else {
tstr_copy = NULL;
}
- dest_tstr_p = (tchar**)((void*)&w->wim_info->images[image - 1] + offset);
+ dest_tstr_p = (tchar**)((void*)&wim->wim_info->images[image - 1] + offset);
FREE(*dest_tstr_p);
*dest_tstr_p = tstr_copy;
/* Sets the description of an image in the WIM. */
WIMLIBAPI int
-wimlib_set_image_descripton(WIMStruct *w, int image,
+wimlib_set_image_descripton(WIMStruct *wim, int image,
const tchar *description)
{
- return do_set_image_info_str(w, image, description,
+ return do_set_image_info_str(wim, image, description,
offsetof(struct image_info, description));
}
/* Set the <FLAGS> element of a WIM image */
WIMLIBAPI int
-wimlib_set_image_flags(WIMStruct *w, int image, const tchar *flags)
+wimlib_set_image_flags(WIMStruct *wim, int image, const tchar *flags)
{
- return do_set_image_info_str(w, image, flags,
+ return do_set_image_info_str(wim, image, flags,
offsetof(struct image_info, flags));
}