+/* If not done already, load the supported feature flags for the volume onto
+ * which the image is being extracted, and warn the user about any missing
+ * features that could be important. */
+static int
+win32_check_vol_flags(const wchar_t *output_path, struct apply_args *args)
+{
+ if (args->have_vol_flags)
+ return 0;
+
+ win32_get_vol_flags(output_path, &args->vol_flags);
+ args->have_vol_flags = true;
+ /* Warn the user about data that may not be extracted. */
+ if (!(args->vol_flags & FILE_SUPPORTS_SPARSE_FILES))
+ WARNING("Volume does not support sparse files!\n"
+ " Sparse files will be extracted as non-sparse.");
+ if (!(args->vol_flags & FILE_SUPPORTS_REPARSE_POINTS))
+ WARNING("Volume does not support reparse points!\n"
+ " Reparse point data will not be extracted.");
+ if (!(args->vol_flags & FILE_NAMED_STREAMS)) {
+ WARNING("Volume does not support named data streams!\n"
+ " Named data streams will not be extracted.");
+ }
+ if (!(args->vol_flags & FILE_SUPPORTS_ENCRYPTION)) {
+ WARNING("Volume does not support encryption!\n"
+ " Encrypted files will be extracted as raw data.");
+ }
+ if (!(args->vol_flags & FILE_FILE_COMPRESSION)) {
+ WARNING("Volume does not support transparent compression!\n"
+ " Compressed files will be extracted as non-compressed.");
+ }
+ if (!(args->vol_flags & FILE_PERSISTENT_ACLS)) {
+ if (args->extract_flags & WIMLIB_EXTRACT_FLAG_STRICT_ACLS) {
+ ERROR("Strict ACLs requested, but the volume does not "
+ "support ACLs!");
+ return WIMLIB_ERR_VOLUME_LACKS_FEATURES;
+ } else {
+ WARNING("Volume does not support persistent ACLS!\n"
+ " File permissions will not be extracted.");
+ }
+ }
+ return 0;
+}
+
+/*
+ * Try extracting a hard link.
+ *
+ * @output_path: Path to link to be extracted.
+ *
+ * @inode: WIM inode that the link is to; inode->i_extracted_file
+ * the path to a name of the file that has already been
+ * extracted (we use this to create the hard link).
+ *
+ * @args: Additional apply context, used here to keep track of
+ * the number of times creating a hard link failed due to
+ * ERROR_INVALID_FUNCTION. This error should indicate that hard
+ * links are not supported by the volume, and we would like to
+ * warn the user a few times, but not too many times.
+ *
+ * Returns 0 if the hard link was successfully extracted. Returns
+ * WIMLIB_ERR_LINK (> 0) if an error occurred, other than hard links possibly
+ * being unsupported by the volume. Returns a negative value if creating the
+ * hard link failed due to ERROR_INVALID_FUNCTION.
+ */
+static int
+win32_try_hard_link(const wchar_t *output_path, const struct wim_inode *inode,
+ struct apply_args *args)
+{
+ DWORD err;
+
+ /* There is a volume flag for this (FILE_SUPPORTS_HARD_LINKS),
+ * but it's only available on Windows 7 and later. So no use
+ * even checking it, really. Instead, CreateHardLinkW() will
+ * apparently return ERROR_INVALID_FUNCTION if the volume does
+ * not support hard links. */
+ DEBUG("Creating hard link \"%ls => %ls\"",
+ output_path, inode->i_extracted_file);
+ if (CreateHardLinkW(output_path, inode->i_extracted_file, NULL))
+ return 0;
+
+ err = GetLastError();
+ if (err != ERROR_INVALID_FUNCTION) {
+ ERROR("Can't create hard link \"%ls => %ls\"",
+ output_path, inode->i_extracted_file);
+ win32_error(err);
+ return WIMLIB_ERR_LINK;
+ } else {
+ args->num_hard_links_failed++;
+ if (args->num_hard_links_failed < MAX_CREATE_HARD_LINK_WARNINGS) {
+ WARNING("Can't create hard link \"%ls => %ls\":\n"
+ " Volume does not support hard links!\n"
+ " Falling back to extracting a copy of the file.",
+ output_path, inode->i_extracted_file);
+ } else if (args->num_hard_links_failed == MAX_CREATE_HARD_LINK_WARNINGS) {
+ WARNING("Suppressing further hard linking warnings...");
+ }
+ return -1;
+ }
+}
+