peass-ng/PEASS-ng · warning · NotSupportedException

Creating hard-links on non-NTFS partitions is not supported.

Error message

Creating hard-links on non-NTFS partitions is not supported.

What it means

Creating a hard link requires filesystem support; NTFS (and ReFS) support hard links while FAT/exFAT and other non-NTFS volumes return ERROR_INVALID_FUNCTION (1) from CreateHardLink. AlphaFS translates that specific Win32 error into NotSupportedException(Resources.HardLinks_Not_Supported).

Source

Thrown at winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File Core Methods/File.CreateHardlinkCore.cs:67

            existingFileName = Path.GetExtendedLengthPathCore(transaction, existingFileName, pathFormat, options);
         }


         if (!(transaction == null || !NativeMethods.IsAtLeastWindowsVista

            // CreateHardLink() / CreateHardLinkTransacted()
            // 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists.
            // 2017-05-30: CreateHardLink() MSDN confirms LongPath usage: Starting with Windows 10, version 1607

            ? NativeMethods.CreateHardLink(fileName, existingFileName, IntPtr.Zero)
            : NativeMethods.CreateHardLinkTransacted(fileName, existingFileName, IntPtr.Zero, transaction.SafeHandle)))
         {
            var lastError = (uint) Marshal.GetLastWin32Error();

            switch (lastError)
            {
               case Win32Errors.ERROR_INVALID_FUNCTION:
                  throw new NotSupportedException(Resources.HardLinks_Not_Supported);

               default:
                  NativeError.ThrowException(lastError, existingFileName, fileName);
                  break;
            }
         }
      }
   }
}

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Ensure both the existing file and the hardlink target are on an NTFS volume; reformat or choose a different drive.
  2. Fall back to a file copy when the volume does not support hard links (check the drive format via DriveInfo).
  3. Handle NotSupportedException explicitly and use an alternative such as a symbolic link (also NTFS-restricted) or a plain copy.

Example fix

// before
File.CreateHardlink(linkPath, existingFile); // NotSupportedException on FAT32
// after
var drive = new DriveInfo(Path.GetPathRoot(existingFile));
if (string.Equals(drive.DriveFormat, "NTFS", StringComparison.OrdinalIgnoreCase))
    File.CreateHardlink(linkPath, existingFile);
else
    File.Copy(existingFile, linkPath);
Defensive patterns

Strategy: try-catch

Validate before calling

static bool SupportsHardLinks(string path)
{
    var root = Path.GetPathRoot(Path.GetFullPath(path));
    var drive = new DriveInfo(root);
    return string.Equals(drive.DriveFormat, "NTFS", StringComparison.OrdinalIgnoreCase)
        || string.Equals(drive.DriveFormat, "ReFS", StringComparison.OrdinalIgnoreCase);
}
// only call File.CreateHardlink if SupportsHardLinks(existingFile) && SupportsHardLinks(linkPath)

Type guard

static bool CanCreateHardlink(string existing, string link) =>
    SupportsHardLinks(existing) && SupportsHardLinks(link);

Try / catch

try { File.CreateHardlink(linkPath, existingFile); }
catch (NotSupportedException)
{
    // non-NTFS volume: fall back to a full copy
    File.Copy(existingFile, linkPath, false);
}

Prevention

When it happens

Trigger: Calling File.CreateHardlink(existingFileName, fileName) (any of the transacted/non-transacted overloads) where either path is on a FAT32/exFAT partition or a non-NTFS volume such as a USB stick or SD card.

Common situations: Running tools that deduplicate or link files on removable USB drives formatted FAT32; Windows-to-Go or WSL-mounted volumes; creating links across volumes where the link target volume is non-NTFS.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/fae1a23c57767bb5. Report an issue: GitHub.