Beispiel #1
0
/* Unlink @subject from the WIM image.
 *
 * This is the journaled version, so it can be rolled back.  */
static int
journaled_unlink(struct update_command_journal *j, struct wim_dentry *subject)
{
	struct wim_dentry *parent;
	struct update_primitive prim;
	int ret;

	if (dentry_is_root(subject))
		parent = NULL;
	else
		parent = subject->d_parent;

	prim.type = UNLINK_DENTRY;
	prim.link.subject = subject;
	prim.link.parent = parent;

	ret = record_update_primitive(j, prim);
	if (ret)
		return ret;

	do_unlink(subject, parent, j->root_p);

	list_add(&subject->tmp_list, &j->orphans);
	subject->is_orphan = 1;
	return 0;
}
Beispiel #2
0
/* Is @d1 a (possibly nonproper) ancestor of @d2?  */
static bool
is_ancestor(const struct wim_dentry *d1, const struct wim_dentry *d2)
{
	for (;;) {
		if (d2 == d1)
			return true;
		if (dentry_is_root(d2))
			return false;
		d2 = d2->d_parent;
	}
}
Beispiel #3
0
/* Returns the number of characters needed to represent the path to the
 * specified @dentry when extracted, not including the null terminator or the
 * path to the target directory itself.  */
static size_t
unix_dentry_path_length(const struct wim_dentry *dentry)
{
	size_t len = 0;
	const struct wim_dentry *d;

	d = dentry;
	do {
		len += d->d_extraction_name_nchars + 1;
		d = d->d_parent;
	} while (!dentry_is_root(d) && will_extract_dentry(d));

	return len;
}
Beispiel #4
0
static int
init_wimlib_dentry(struct wimlib_dir_entry *wdentry, struct wim_dentry *dentry,
		   WIMStruct *wim, int flags)
{
	int ret;
	size_t dummy;
	const struct wim_inode *inode = dentry->d_inode;
	const struct wim_inode_stream *strm;
	struct wimlib_unix_data unix_data;
	const void *object_id;
	u32 object_id_len;

	ret = utf16le_get_tstr(dentry->d_name, dentry->d_name_nbytes,
			       &wdentry->filename, &dummy);
	if (ret)
		return ret;

	ret = utf16le_get_tstr(dentry->d_short_name, dentry->d_short_name_nbytes,
			       &wdentry->dos_name, &dummy);
	if (ret)
		return ret;

	ret = calculate_dentry_full_path(dentry);
	if (ret)
		return ret;
	wdentry->full_path = dentry->d_full_path;

	for (struct wim_dentry *d = dentry; !dentry_is_root(d); d = d->d_parent)
		wdentry->depth++;

	if (inode_has_security_descriptor(inode)) {
		struct wim_security_data *sd;

		sd = wim_get_current_security_data(wim);
		wdentry->security_descriptor = sd->descriptors[inode->i_security_id];
		wdentry->security_descriptor_size = sd->sizes[inode->i_security_id];
	}
	wdentry->reparse_tag = inode->i_reparse_tag;
	wdentry->num_links = inode->i_nlink;
	wdentry->attributes = inode->i_attributes;
	wdentry->hard_link_group_id = inode->i_ino;
	wdentry->creation_time = wim_timestamp_to_timespec(inode->i_creation_time);
	wdentry->last_write_time = wim_timestamp_to_timespec(inode->i_last_write_time);
	wdentry->last_access_time = wim_timestamp_to_timespec(inode->i_last_access_time);
	if (inode_get_unix_data(inode, &unix_data)) {
		wdentry->unix_uid = unix_data.uid;
		wdentry->unix_gid = unix_data.gid;
		wdentry->unix_mode = unix_data.mode;
		wdentry->unix_rdev = unix_data.rdev;
	}
	object_id = inode_get_object_id(inode, &object_id_len);
	if (unlikely(object_id != NULL)) {
		memcpy(&wdentry->object_id, object_id,
		       min(object_id_len, sizeof(wdentry->object_id)));
	}

	strm = inode_get_unnamed_stream(inode, get_default_stream_type(inode));
	if (strm) {
		ret = stream_to_wimlib_stream_entry(inode, strm,
						    &wdentry->streams[0],
						    wim->blob_table, flags);
		if (ret)
			return ret;
	}

	for (unsigned i = 0; i < inode->i_num_streams; i++) {

		strm = &inode->i_streams[i];

		if (!stream_is_named_data_stream(strm))
			continue;

		wdentry->num_named_streams++;

		ret = stream_to_wimlib_stream_entry(inode, strm,
						    &wdentry->streams[
							wdentry->num_named_streams],
						    wim->blob_table, flags);
		if (ret)
			return ret;
	}
	return 0;
}