wimlib_assert(lte);
wimlib_assert(lte->num_opened_fds);
- if (lte->staging_file_name) {
+ if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
+ wimlib_assert(lte->staging_file_name);
wimlib_assert(fd->staging_fd != -1);
if (close(fd->staging_fd) != 0)
return -errno;
}
if (--lte->num_opened_fds == 0 && lte->refcnt == 0) {
- if (lte->staging_file_name)
+ if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
+ wimlib_assert(lte->staging_file_name);
unlink(lte->staging_file_name);
+ }
free_lookup_table_entry(lte);
}
wimlib_assert(lte->fds[fd->idx] == fd);
/* Use the size of the unnamed (default) file stream. */
lte = dentry_first_lte_resolved(dentry);
if (lte) {
- if (lte->staging_file_name) {
+ if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
+ wimlib_assert(lte->staging_file_name);
struct stat native_stat;
if (stat(lte->staging_file_name, &native_stat) != 0) {
DEBUG("Failed to stat `%s': %m",
return -errno;
if (old_lte)
- ret = extract_resource_to_fd(w, &old_lte->resource_entry, fd,
- size);
+ ret = extract_wim_resource_to_fd(old_lte, fd, size);
else
ret = 0;
if (ret != 0 || close(fd) != 0) {
new_lte->refcnt = link_group_size;
random_hash(new_lte->hash);
new_lte->staging_file_name = staging_file_name;
+ new_lte->resource_location = RESOURCE_IN_STAGING_FILE;
lookup_table_insert(w->lookup_table, new_lte);
list_add(&new_lte->staging_list, &staging_list);
{
for (u16 i = 0, j = 0; j < lte->num_opened_fds; i++) {
if (lte->fds[i] && lte->fds[i]->staging_fd != -1) {
+ wimlib_assert(lte->resource_location == RESOURCE_IN_STAGING_FILE);
+ wimlib_assert(lte->staging_file_name);
if (close(lte->fds[i]->staging_fd) != 0) {
ERROR_WITH_ERRNO("Failed close file `%s'",
lte->staging_file_name);
}
-static int calculate_sha1sum_of_staging_file(struct lookup_table_entry *lte,
- struct lookup_table *table)
+static int update_lte_of_staging_file(struct lookup_table_entry *lte,
+ struct lookup_table *table)
{
struct lookup_table_entry *duplicate_lte;
int ret;
u8 hash[SHA1_HASH_SIZE];
+ struct stat stbuf;
+
+ wimlib_assert(lte->resource_location == RESOURCE_IN_STAGING_FILE);
+ wimlib_assert(lte->staging_file_name);
ret = sha1sum(lte->staging_file_name, hash);
if (ret != 0)
return ret;
lookup_table_unlink(table, lte);
- copy_hash(lte->hash, hash);
duplicate_lte = __lookup_resource(table, hash);
lte_list_change_lte_ptr(lte, duplicate_lte);
duplicate_lte->refcnt += lte->refcnt;
- list_splice(&duplicate_lte->lte_group_list,
- <e->lte_group_list);
+ list_splice(<e->lte_group_list,
+ &duplicate_lte->lte_group_list);
free_lookup_table_entry(lte);
} else {
+ if (stat(lte->staging_file_name, &stbuf) != 0) {
+ ERROR_WITH_ERRNO("Failed to stat `%s'", lte->staging_file_name);
+ return WIMLIB_ERR_STAT;
+ }
+ wimlib_assert(<e->file_on_disk == <e->staging_file_name);
+ lte->resource_location = RESOURCE_IN_FILE_ON_DISK;
+ copy_hash(lte->hash, hash);
+ lte->resource_entry.original_size = stbuf.st_size;
+ lte->resource_entry.size = stbuf.st_size;
lookup_table_insert(table, lte);
}
* lookup table entries. */
DEBUG("Calculating SHA1 checksums for all new staging files.");
list_for_each_entry_safe(lte, tmp, &staging_list, staging_list) {
- ret = calculate_sha1sum_of_staging_file(lte, w->lookup_table);
+ ret = update_lte_of_staging_file(lte, w->lookup_table);
if (ret != 0)
return ret;
}
if (ret != 0)
return ret;
}
- if (lte->staging_file_name) {
+ if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
fd->staging_fd = open(lte->staging_file_name, fi->flags);
if (fd->staging_fd == -1) {
close_wimlib_fd(fd);
wimlib_assert(fd->lte);
- if (fd->lte->staging_file_name) {
+ if (fd->lte->resource_location == RESOURCE_IN_STAGING_FILE) {
/* Read from staging file */
+ wimlib_assert(fd->lte->staging_file_name);
wimlib_assert(fd->staging_fd != -1);
ssize_t ret;
} else {
/* Read from WIM */
- struct resource_entry *res_entry;
- int ctype;
+ const struct resource_entry *res_entry;
res_entry = &fd->lte->resource_entry;
- ctype = wim_resource_compression_type(w, res_entry);
-
if (offset > res_entry->original_size)
return -EOVERFLOW;
size = min(size, res_entry->original_size - offset);
- if (read_resource(w->fp, res_entry->size,
- res_entry->original_size,
- res_entry->offset, ctype, size,
- offset, buf) != 0)
+ if (read_wim_resource(fd->lte, buf, size, offset, false) != 0)
return -EIO;
return size;
}
if (!p)
return WIMLIB_ERR_NOMEM;
- argv[argc++] = "mount";
+ argv[argc++] = "imagex";
argv[argc++] = p;
argv[argc++] = "-s"; /* disable multi-threaded operation */