void free_lookup_table_entry(struct lookup_table_entry *lte)
{
if (lte) {
+#ifdef WITH_FUSE
if (lte->staging_list.next)
list_del(<e->staging_list);
- if (lte->resource_location != RESOURCE_IN_WIM &&
- lte->resource_location != RESOURCE_NONEXISTENT)
+#endif
+ switch (lte->resource_location) {
+ case RESOURCE_IN_STAGING_FILE:
+ case RESOURCE_IN_ATTACHED_BUFFER:
+ case RESOURCE_IN_FILE_ON_DISK:
+ wimlib_assert(<e->file_on_disk ==
+ <e->staging_file_name ==
+ <e->attached_buffer);
FREE(lte->file_on_disk);
+ break;
+#ifdef WITH_NTFS_3G
+ case RESOURCE_IN_NTFS_VOLUME:
+ if (lte->ntfs_loc) {
+ FREE(lte->ntfs_loc->path_utf8);
+ FREE(lte->ntfs_loc->stream_name_utf16);
+ FREE(lte->ntfs_loc);
+ }
+ break;
+#endif
+ default:
+ break;
+ }
FREE(lte);
}
}
#include <unistd.h>
/** Private flag: Used to mark that we currently adding the root directory of
- * the WIM. */
+ * the WIM image. */
#define WIMLIB_ADD_IMAGE_FLAG_ROOT 0x80000000
void destroy_image_metadata(struct image_metadata *imd,struct lookup_table *lt)
ALIGNMENT_LIST,
};
+/* Default capture configuration file when none is specified. */
static const char *default_config =
"[ExclusionList]\n"
"\\$ntfs.log\n"
return 0;
}
+/* Parses the contents of the image capture configuration file and fills in a
+ * `struct capture_config'. */
static int init_capture_config(const char *_config_str, size_t config_len,
const char *_prefix, struct capture_config *config)
{
}
}
+/* Return true if the image capture configuration file indicates we should
+ * exclude the filename @path from capture.
+ *
+ * If @exclude_prefix is %true, the part of the path up and including the name
+ * of the directory being captured is not included in the path for matching
+ * purposes. This allows, for example, a pattern like /hiberfil.sys to match a
+ * file /mnt/windows7/hiberfil.sys if we are capturing the /mnt/windows7
+ * directory.
+ */
bool exclude_path(const char *path, const struct capture_config *config,
bool exclude_prefix)
{
+/*
+ * Adds an image to the WIM, delegating the capture of the dentry tree and
+ * security data to the function @capture_tree passed as a parameter.
+ * Currently, @capture_tree may be build_dentry_tree() for capturing a "regular"
+ * directory tree on disk, or build_dentry_tree_ntfs() for capturing a WIM image
+ * directory from a NTFS volume using libntfs-3g.
+ *
+ * The @capture_tree function is also expected to create lookup table entries
+ * for all the file streams it captures and insert them into @lookup_table,
+ * being careful to look for identical entries that already exist and simply
+ * increment the reference count for them rather than duplicating the entry.
+ */
int do_add_image(WIMStruct *w, const char *dir, const char *name,
const char *config_str, size_t config_len,
int flags,
struct link_group_table *lgt;
int ret;
- DEBUG("Adding dentry tree from dir `%s'.", dir);
+ DEBUG("Adding dentry tree from directory or NTFS volume `%s'.", dir);
if (!name || !*name) {
ERROR("Must specify a non-empty string for the image name");
return WIMLIB_ERR_INVALID_PARAM;
}
if (!dir) {
- ERROR("Must specify the name of a directory");
+ ERROR("Must specify the name of a directory or NTFS volume");
return WIMLIB_ERR_INVALID_PARAM;
}
sd->descriptors[sd->num_entries] = descr_copy;
sd->sizes[sd->num_entries] = size;
sd->num_entries++;
+ DEBUG("There are now %d security descriptors", sd->num_entries);
sd->total_length += size + sizeof(sd->sizes[0]);
if (sd_set->root)
/* Get context to search the streams of the NTFS file. */
actx = ntfs_attr_get_search_ctx(ni, NULL);
if (!actx) {
- ERROR_WITH_ERRNO("Cannot get attribute search "
+ ERROR_WITH_ERRNO("Cannot get NTFS attribute search "
"context");
return WIMLIB_ERR_NTFS_3G;
}
dentry->lte = lte;
} else {
struct ads_entry *new_ads_entry;
+ size_t stream_name_utf8_len;
stream_name_utf8 = utf16_to_utf8((const char*)attr_record_name(actx->attr),
actx->attr->name_length,
- &stream_name_utf16_len);
+ &stream_name_utf8_len);
if (!stream_name_utf8)
goto out_free_lte;
new_ads_entry = dentry_add_ads(dentry, stream_name_utf8);
*/
static int build_dentry_tree_ntfs_recursive(struct dentry **root_p,
ntfs_inode *ni,
- char path[], size_t path_len,
+ char path[],
+ size_t path_len,
struct lookup_table *lookup_table,
struct sd_set *sd_set,
const struct capture_config *config,
{
u32 attributes;
int mrec_flags;
- u32 sd_size;
+ u32 sd_size = 0;
int ret = 0;
struct dentry *root;
root->creation_time = le64_to_cpu(ni->creation_time);
root->last_write_time = le64_to_cpu(ni->last_data_change_time);
root->last_access_time = le64_to_cpu(ni->last_access_time);
- root->security_id = le32_to_cpu(ni->security_id);
root->attributes = le32_to_cpu(attributes);
root->link_group_id = ni->mft_no;
root->resolved = true;
if (ret > 0) {
/*print_security_descriptor(sd, sd_size);*/
root->security_id = sd_set_add_sd(sd_set, sd, sd_size);
+ if (root->security_id == -1) {
+ ERROR("Out of memory");
+ return WIMLIB_ERR_NOMEM;
+ }
DEBUG("Added security ID = %u for `%s'",
root->security_id, path);
} else {
ntfs_volume *vol;
ntfs_inode *root_ni;
int ret = 0;
- struct sd_set sd_set;
- sd_set.sd = sd;
- sd_set.root = NULL;
+ struct sd_set sd_set = {
+ .sd = sd,
+ .root = NULL,
+ };
ntfs_volume **ntfs_vol_p = extra_arg;
DEBUG("Mounting NTFS volume `%s' read-only", device);
return WIMLIB_ERR_NTFS_3G;
}
+ /* We don't want to capture the special NTFS files such as $Bitmap. Not
+ * to be confused with "hidden" or "system" files which are real files
+ * that we do need to capture. */
NVolClearShowSysFiles(vol);
DEBUG("Opening root NTFS dentry");
ret = WIMLIB_ERR_NTFS_3G;
goto out;
}
- char *path = MALLOC(32769);
+
+ /* Currently we assume that all the UTF-8 paths fit into this length and
+ * there is no check for overflow. */
+ char *path = MALLOC(32768);
if (!path) {
ERROR("Could not allocate memory for NTFS pathname");
goto out_cleanup;
}
+
path[0] = '/';
path[1] = '\0';
ret = build_dentry_tree_ntfs_recursive(root_p, root_ni, path, 1,
ret = WIMLIB_ERR_NTFS_3G;
}
} else {
+ /* We need to leave the NTFS volume mounted so that we can read
+ * the NTFS files again when we are actually writing the WIM */
*ntfs_vol_p = vol;
}
return ret;