#include "config.h"
-#ifdef WITH_NTFS_3G
#include <ntfs-3g/endians.h>
#include <ntfs-3g/types.h>
-#endif
#include "wimlib_internal.h"
-#ifdef WITH_NTFS_3G
#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>
*/
static int ntfs_attr_sha1sum(ntfs_inode *ni, ATTR_RECORD *ar,
u8 md[SHA1_HASH_SIZE],
+ bool is_reparse_point,
u32 *reparse_tag_ret)
{
s64 pos = 0;
s64 bytes_remaining;
- char buf[4096];
+ char buf[BUFFER_SIZE];
ntfs_attr *na;
SHA_CTX ctx;
}
bytes_remaining = na->data_size;
- sha1_init(&ctx);
- DEBUG2("Calculating SHA1 message digest (%"PRIu64" bytes)",
- bytes_remaining);
+ if (is_reparse_point) {
+ if (ntfs_attr_pread(na, 0, 8, buf) != 8)
+ goto out_error;
+ *reparse_tag_ret = le32_to_cpu(*(u32*)buf);
+ pos = 8;
+ bytes_remaining -= 8;
+ }
+ sha1_init(&ctx);
while (bytes_remaining) {
s64 to_read = min(bytes_remaining, sizeof(buf));
- if (ntfs_attr_pread(na, pos, to_read, buf) != to_read) {
- ERROR_WITH_ERRNO("Error reading NTFS attribute");
- return WIMLIB_ERR_NTFS_3G;
- }
- if (bytes_remaining == na->data_size && reparse_tag_ret)
- *reparse_tag_ret = le32_to_cpu(*(u32*)buf);
+ if (ntfs_attr_pread(na, pos, to_read, buf) != to_read)
+ goto out_error;
sha1_update(&ctx, buf, to_read);
pos += to_read;
bytes_remaining -= to_read;
sha1_final(md, &ctx);
ntfs_attr_close(na);
return 0;
+out_error:
+ ERROR_WITH_ERRNO("Error reading NTFS attribute");
+ return WIMLIB_ERR_NTFS_3G;
}
-/* Load the streams from a WIM file or reparse point in the NTFS volume into the
- * WIM lookup table */
+/* Load the streams from a file or reparse point in the NTFS volume into the WIM
+ * lookup table */
static int capture_ntfs_streams(struct dentry *dentry, ntfs_inode *ni,
char path[], size_t path_len,
struct lookup_table *lookup_table,
CASE_SENSITIVE, 0, NULL, 0, actx))
{
char *stream_name_utf8;
- size_t stream_name_utf16_len;
u32 reparse_tag;
u64 data_size = ntfs_get_attribute_value_length(actx->attr);
u64 name_length = actx->attr->name_length;
goto out_put_actx;
}
/* Checksum the stream. */
- ret = ntfs_attr_sha1sum(ni, actx->attr, attr_hash, &reparse_tag);
+ ret = ntfs_attr_sha1sum(ni, actx->attr, attr_hash,
+ type == AT_REPARSE_POINT, &reparse_tag);
if (ret != 0)
goto out_put_actx;
struct sd_set *sd_set;
const struct capture_config *config;
ntfs_volume **ntfs_vol_p;
- int flags;
+ int add_image_flags;
+ wimlib_progress_func_t progress_func;
};
static int
struct sd_set *sd_set,
const struct capture_config *config,
ntfs_volume **ntfs_vol_p,
- int flags);
+ int add_image_flags,
+ wimlib_progress_func_t progress_func);
static int wim_ntfs_capture_filldir(void *dirent, const ntfschar *name,
const int name_len, const int name_type,
ni, ctx->path, path_len, name_type,
ctx->lookup_table, ctx->sd_set,
ctx->config, ctx->ntfs_vol_p,
- ctx->flags);
+ ctx->add_image_flags,
+ ctx->progress_func);
if (child)
- link_dentry(child, ctx->parent);
+ dentry_add_child(ctx->parent, child);
ntfs_inode_close(ni);
out_free_utf8_name:
struct sd_set *sd_set,
const struct capture_config *config,
ntfs_volume **ntfs_vol_p,
- int flags)
+ int add_image_flags,
+ wimlib_progress_func_t progress_func)
{
u32 attributes;
int mrec_flags;
- u32 sd_size = 0;
int ret;
char dos_name_utf8[64];
struct dentry *root;
+ if (exclude_path(path, config, false)) {
+ if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
+ && progress_func)
+ {
+ union wimlib_progress_info info;
+ info.scan.cur_path = path;
+ info.scan.excluded = true;
+ progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
+ }
+ *root_p = NULL;
+ return 0;
+ }
+
mrec_flags = ni->mrec->flags;
struct SECURITY_CONTEXT ctx;
memset(&ctx, 0, sizeof(ctx));
return WIMLIB_ERR_NTFS_3G;
}
- if (exclude_path(path, config, false)) {
- if (flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE) {
- const char *file_type;
- if (attributes & MFT_RECORD_IS_DIRECTORY)
- file_type = "directory";
- else
- file_type = "file";
- printf("Excluding %s `%s' from capture\n",
- file_type, path);
- }
- *root_p = NULL;
- return 0;
+ if ((add_image_flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
+ && progress_func)
+ {
+ union wimlib_progress_info info;
+ info.scan.cur_path = path;
+ info.scan.excluded = false;
+ progress_func(WIMLIB_PROGRESS_MSG_SCAN_DENTRY, &info);
}
- if (flags & WIMLIB_ADD_IMAGE_FLAG_VERBOSE)
- printf("Scanning `%s'\n", path);
-
root = new_dentry_with_timeless_inode(path_basename(path));
if (!root)
return WIMLIB_ERR_NOMEM;
.sd_set = sd_set,
.config = config,
.ntfs_vol_p = ntfs_vol_p,
- .flags = flags,
+ .add_image_flags = add_image_flags,
+ .progress_func = progress_func,
};
ret = ntfs_readdir(ni, &pos, &ctx, wim_ntfs_capture_filldir);
if (ret != 0) {
return ret;
}
-static int build_dentry_tree_ntfs(struct dentry **root_p,
- const char *device,
- struct lookup_table *lookup_table,
- struct wim_security_data *sd,
- const struct capture_config *config,
- int flags,
- void *extra_arg)
+int build_dentry_tree_ntfs(struct dentry **root_p,
+ const char *device,
+ struct lookup_table *lookup_table,
+ struct wim_security_data *sd,
+ const struct capture_config *config,
+ int add_image_flags,
+ wimlib_progress_func_t progress_func,
+ void *extra_arg)
{
ntfs_volume *vol;
ntfs_inode *root_ni;
ret = build_dentry_tree_ntfs_recursive(root_p, NULL, root_ni, path, 1,
FILE_NAME_POSIX, lookup_table,
&sd_set, config, ntfs_vol_p,
- flags);
+ add_image_flags,
+ progress_func);
out_cleanup:
FREE(path);
ntfs_inode_close(root_ni);
}
return ret;
}
-
-
-
-WIMLIBAPI int wimlib_add_image_from_ntfs_volume(WIMStruct *w,
- const char *device,
- const char *name,
- const char *config_str,
- size_t config_len,
- int flags)
-{
- if (flags & (WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE)) {
- ERROR("Cannot dereference files when capturing directly from NTFS");
- return WIMLIB_ERR_INVALID_PARAM;
- }
- return do_add_image(w, device, name, config_str, config_len, flags,
- build_dentry_tree_ntfs, &w->ntfs_vol);
-}
-
-#else /* WITH_NTFS_3G */
-WIMLIBAPI int wimlib_add_image_from_ntfs_volume(WIMStruct *w,
- const char *device,
- const char *name,
- const char *config_str,
- size_t config_len,
- int flags)
-{
- ERROR("wimlib was compiled without support for NTFS-3g, so");
- ERROR("we cannot capture a WIM image directly from a NTFS volume");
- return WIMLIB_ERR_UNSUPPORTED;
-}
-#endif /* WITH_NTFS_3G */