#include "wimlib_internal.h"
#include "dentry.h"
#include "lookup_table.h"
-#include "io.h"
+#include "buffer_io.h"
#include <ntfs-3g/layout.h>
#include <ntfs-3g/acls.h>
#include <ntfs-3g/attrib.h>
#include <stdlib.h>
#include <unistd.h>
+static int extract_wim_chunk_to_ntfs_attr(const u8 *buf, size_t len,
+ u64 offset, void *arg)
+{
+ ntfs_attr *na = arg;
+ if (ntfs_attr_pwrite(na, offset, len, buf) == len) {
+ return 0;
+ } else {
+ ERROR_WITH_ERRNO("Error extracting WIM resource to NTFS attribute");
+ return WIMLIB_ERR_WRITE;
+ }
+}
+
/*
* Extracts a WIM resource to a NTFS attribute.
*/
extract_wim_resource_to_ntfs_attr(const struct lookup_table_entry *lte,
ntfs_attr *na)
{
- u64 bytes_remaining = wim_resource_size(lte);
- u8 buf[min(WIM_CHUNK_SIZE, bytes_remaining)];
- u64 offset = 0;
- int ret = 0;
- u8 hash[SHA1_HASH_SIZE];
-
- SHA_CTX ctx;
- sha1_init(&ctx);
-
- while (bytes_remaining) {
- u64 to_read = min(bytes_remaining, WIM_CHUNK_SIZE);
- ret = read_wim_resource(lte, buf, to_read, offset, 0);
- if (ret != 0)
- break;
- sha1_update(&ctx, buf, to_read);
- if (ntfs_attr_pwrite(na, offset, to_read, buf) != to_read) {
- ERROR_WITH_ERRNO("Error extracting WIM resource");
- return WIMLIB_ERR_WRITE;
- }
- bytes_remaining -= to_read;
- offset += to_read;
- }
- sha1_final(hash, &ctx);
- if (!hashes_equal(hash, lte->hash)) {
- ERROR("Invalid checksum on a WIM resource "
- "(detected when extracting to NTFS stream)");
- ERROR("The following WIM resource is invalid:");
- print_lookup_table_entry(lte);
- return WIMLIB_ERR_INVALID_RESOURCE_HASH;
- }
- return 0;
+ return extract_wim_resource(lte, wim_resource_size(lte),
+ extract_wim_chunk_to_ntfs_attr, na);
}
/* Writes the data streams to a NTFS file
*
* Return 0 on success, nonzero on failure.
*/
-static int wim_apply_hardlink_ntfs(const struct dentry *from_dentry,
- const struct inode *inode,
- ntfs_inode *dir_ni,
- ntfs_inode **to_ni_ret)
+static int apply_hardlink_ntfs(const struct dentry *from_dentry,
+ const struct inode *inode,
+ ntfs_inode *dir_ni,
+ ntfs_inode **to_ni_ret)
{
int ret;
char *p;
return 0;
}
-static int do_wim_apply_dentry_ntfs(struct dentry *dentry, ntfs_inode *dir_ni,
- struct apply_args *args);
+static int do_apply_dentry_ntfs(struct dentry *dentry, ntfs_inode *dir_ni,
+ struct apply_args *args);
/*
* If @dentry is part of a hard link group, search for hard-linked dentries in
DEBUG("pre-applying DOS name `%s'",
dentry_with_dos_name->full_path_utf8);
- ret = do_wim_apply_dentry_ntfs(dentry_with_dos_name,
- *dir_ni_p, args);
+ ret = do_apply_dentry_ntfs(dentry_with_dos_name,
+ *dir_ni_p, args);
if (ret != 0)
return ret;
p = dentry->full_path_utf8 + dentry->full_path_utf8_len;
*
* @return: 0 on success; nonzero on failure.
*/
-static int do_wim_apply_dentry_ntfs(struct dentry *dentry, ntfs_inode *dir_ni,
- struct apply_args *args)
+static int do_apply_dentry_ntfs(struct dentry *dentry, ntfs_inode *dir_ni,
+ struct apply_args *args)
{
int ret = 0;
mode_t type;
* group. We can make a hard link instead of extracting
* the file data. */
if (inode->extracted_file) {
- ret = wim_apply_hardlink_ntfs(dentry, inode,
- dir_ni, &ni);
+ ret = apply_hardlink_ntfs(dentry, inode,
+ dir_ni, &ni);
is_hardlink = true;
if (ret)
goto out_close_dir_ni;
char *short_name_utf8;
size_t short_name_utf8_len;
- short_name_utf8 = utf16_to_utf8(dentry->short_name,
- dentry->short_name_len,
- &short_name_utf8_len);
- if (!short_name_utf8) {
- ERROR("Out of memory");
- ret = WIMLIB_ERR_NOMEM;
+ ret = utf16_to_utf8(dentry->short_name,
+ dentry->short_name_len,
+ &short_name_utf8,
+ &short_name_utf8_len);
+ if (ret != 0)
goto out_close_dir_ni;
- }
if (is_hardlink) {
char *p;
return ret;
}
-static int wim_apply_root_dentry_ntfs(const struct dentry *dentry,
- ntfs_volume *vol,
- const WIMStruct *w)
+static int apply_root_dentry_ntfs(const struct dentry *dentry,
+ ntfs_volume *vol, const WIMStruct *w)
{
ntfs_inode *ni;
int ret = 0;
}
/* Applies a WIM dentry to the NTFS volume */
-int wim_apply_dentry_ntfs(struct dentry *dentry, void *arg)
+int apply_dentry_ntfs(struct dentry *dentry, void *arg)
{
struct apply_args *args = arg;
ntfs_volume *vol = args->vol;
if (inode_unnamed_lte_resolved(dentry->d_inode))
return 0;
-
DEBUG("Applying dentry `%s' to NTFS", dentry->full_path_utf8);
if ((extract_flags & WIMLIB_EXTRACT_FLAG_VERBOSE) &&
}
if (dentry_is_root(dentry))
- return wim_apply_root_dentry_ntfs(dentry, vol, w);
+ return apply_root_dentry_ntfs(dentry, vol, w);
p = dentry->full_path_utf8 + dentry->full_path_utf8_len;
do {
dir_name);
return WIMLIB_ERR_NTFS_3G;
}
- return do_wim_apply_dentry_ntfs(dentry, dir_ni, arg);
+ return do_apply_dentry_ntfs(dentry, dir_ni, arg);
}
-int wim_apply_dentry_timestamps(struct dentry *dentry, void *arg)
+int apply_dentry_timestamps_ntfs(struct dentry *dentry, void *arg)
{
struct apply_args *args = arg;
ntfs_volume *vol = args->vol;