Example #1
0
static int
stream_to_wimlib_stream_entry(const struct wim_inode *inode,
			      const struct wim_inode_stream *strm,
			      struct wimlib_stream_entry *wstream,
			      const struct blob_table *blob_table,
			      int flags)
{
	const struct blob_descriptor *blob;
	const u8 *hash;

	if (stream_is_named(strm)) {
		size_t dummy;
		int ret;

		ret = utf16le_get_tstr(strm->stream_name,
				       utf16le_len_bytes(strm->stream_name),
				       &wstream->stream_name, &dummy);
		if (ret)
			return ret;
	}

	blob = stream_blob(strm, blob_table);
	if (blob) {
		blob_to_wimlib_resource_entry(blob, &wstream->resource);
	} else if (!is_zero_hash((hash = stream_hash(strm)))) {
		if (flags & WIMLIB_ITERATE_DIR_TREE_FLAG_RESOURCES_NEEDED)
			return blob_not_found_error(inode, hash);
		copy_hash(wstream->resource.sha1_hash, hash);
		wstream->resource.is_missing = 1;
	}
	return 0;
}
Example #2
0
/* Restore the DOS name of the @dentry.
 * This closes both @ni and @dir_ni.
 * If either is NULL, then they are opened temporarily.  */
static int
ntfs_3g_restore_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni,
			 struct wim_dentry *dentry, ntfs_volume *vol)
{
	int ret;
	const char *dos_name;
	size_t dos_name_nbytes;

	/* Note: ntfs_set_ntfs_dos_name() closes both inodes (even if it fails).
	 * And it takes in a multibyte string, even though it translates it to
	 * UTF-16LE internally... which is annoying because we currently have
	 * the UTF-16LE string but not the multibyte string.  */

	ret = utf16le_get_tstr(dentry->short_name, dentry->short_name_nbytes,
			       &dos_name, &dos_name_nbytes);
	if (ret)
		goto out_close;

	if (!dir_ni)
		dir_ni = ntfs_inode_open(vol, dentry->d_parent->d_inode->i_mft_no);
	if (!ni)
		ni = ntfs_inode_open(vol, dentry->d_inode->i_mft_no);
	if (dir_ni && ni) {
		ret = ntfs_set_ntfs_dos_name(ni, dir_ni,
					     dos_name, dos_name_nbytes, 0);
		dir_ni = NULL;
		ni = NULL;
	} else {
		ret = -1;
	}
	utf16le_put_tstr(dos_name);
	if (ret) {
		ERROR_WITH_ERRNO("Failed to set DOS name of \"%s\" in NTFS "
				 "volume", dentry_full_path(dentry));
		ret = WIMLIB_ERR_SET_SHORT_NAME;
		goto out_close;
	}

	/* Unlike most other NTFS-3g functions, ntfs_set_ntfs_dos_name()
	 * changes the directory's last modification timestamp...
	 * Change it back.  */
	return ntfs_3g_restore_timestamps(vol, dentry->d_parent->d_inode);

out_close:
	/* ntfs_inode_close() can take a NULL argument, but it's probably best
	 * not to rely on this behavior.  */
	if (ni)
		ntfs_inode_close(ni);
	if (dir_ni)
		ntfs_inode_close(dir_ni);
	return ret;
}
Example #3
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;
}