- /* Normal mode of extraction. Regular files and hard links are
- * extracted in the way that they appear in the WIM. */
-
- int out_fd;
- int ret;
- struct wim_inode *inode = dentry->d_inode;
-
- if (!((args->extract_flags & WIMLIB_EXTRACT_FLAG_MULTI_IMAGE)
- && (args->extract_flags & (WIMLIB_EXTRACT_FLAG_SYMLINK |
- WIMLIB_EXTRACT_FLAG_HARDLINK))))
- {
- /* If the dentry is part of a hard link set of at least 2
- * dentries and one of the other dentries has already been
- * extracted, make a hard link to the file corresponding to this
- * already-extracted directory. Otherwise, extract the file and
- * set the inode->i_extracted_file field so that other dentries
- * in the hard link group can link to it. */
- if (inode->i_nlink > 1) {
- if (inode->i_extracted_file) {
- DEBUG("Extracting hard link `%s' => `%s'",
- output_path, inode->i_extracted_file);
- if (link(inode->i_extracted_file, output_path) != 0) {
- ERROR_WITH_ERRNO("Failed to hard link "
- "`%s' to `%s'",
- output_path,
- inode->i_extracted_file);
- return WIMLIB_ERR_LINK;
- }
- return 0;
- }
- FREE(inode->i_extracted_file);
- inode->i_extracted_file = STRDUP(output_path);
- if (!inode->i_extracted_file) {
- ERROR("Failed to allocate memory for filename");
- return WIMLIB_ERR_NOMEM;
- }
- }
- }
-
- /* Extract the contents of the file to @output_path. */
-
- out_fd = open(output_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (out_fd == -1) {
- ERROR_WITH_ERRNO("Failed to open the file `%s' for writing",
- output_path);
- return WIMLIB_ERR_OPEN;
- }
-
- if (!lte) {
- /* Empty file with no lookup table entry */
- DEBUG("Empty file `%s'.", output_path);
- ret = 0;
- goto out_extract_unix_data;
- }
-
- ret = extract_wim_resource_to_fd(lte, out_fd, wim_resource_size(lte));
- if (ret) {
- ERROR("Failed to extract resource to `%s'", output_path);
- goto out;
- }
-
-out_extract_unix_data:
- if (args->extract_flags & WIMLIB_EXTRACT_FLAG_UNIX_DATA) {
- struct wimlib_unix_data unix_data;
- ret = inode_get_unix_data(inode, &unix_data, NULL);
- if (ret > 0)
- ;
- else if (ret < 0)
- ret = 0;
- else
- ret = fd_apply_unix_data(out_fd, output_path, &unix_data,
- args->extract_flags);
- if (ret)
- goto out;
- }
- if (lte)
- args->progress.extract.completed_bytes += wim_resource_size(lte);
-out:
- if (close(out_fd) != 0) {
- ERROR_WITH_ERRNO("Failed to close file `%s'", output_path);
- if (ret == 0)
- ret = WIMLIB_ERR_WRITE;