{"record":{"id":"fae1a23c57767bb5","repo":"peass-ng/PEASS-ng","slug":"creating-hard-links-on-non-ntfs-partitions-is-not","errorCode":null,"errorMessage":"Creating hard-links on non-NTFS partitions is not supported.","messagePattern":"Creating hard-links on non-NTFS partitions is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File Core Methods/File.CreateHardlinkCore.cs","lineNumber":67,"sourceCode":"            existingFileName = Path.GetExtendedLengthPathCore(transaction, existingFileName, pathFormat, options);\n         }\n\n\n         if (!(transaction == null || !NativeMethods.IsAtLeastWindowsVista\n\n            // CreateHardLink() / CreateHardLinkTransacted()\n            // 2013-01-13: MSDN does not confirm LongPath usage but a Unicode version of this function exists.\n            // 2017-05-30: CreateHardLink() MSDN confirms LongPath usage: Starting with Windows 10, version 1607\n\n            ? NativeMethods.CreateHardLink(fileName, existingFileName, IntPtr.Zero)\n            : NativeMethods.CreateHardLinkTransacted(fileName, existingFileName, IntPtr.Zero, transaction.SafeHandle)))\n         {\n            var lastError = (uint) Marshal.GetLastWin32Error();\n\n            switch (lastError)\n            {\n               case Win32Errors.ERROR_INVALID_FUNCTION:\n                  throw new NotSupportedException(Resources.HardLinks_Not_Supported);\n\n               default:\n                  NativeError.ThrowException(lastError, existingFileName, fileName);\n                  break;\n            }\n         }\n      }\n   }\n}\n","sourceCodeStart":49,"sourceCodeEnd":77,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/AlphaFS/Filesystem/File Class/File Core Methods/File.CreateHardlinkCore.cs#L49-L77","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure both the existing file and the hardlink target are on an NTFS volume; reformat or choose a different drive.","Fall back to a file copy when the volume does not support hard links (check the drive format via DriveInfo).","Handle NotSupportedException explicitly and use an alternative such as a symbolic link (also NTFS-restricted) or a plain copy."],"exampleFix":"// before\nFile.CreateHardlink(linkPath, existingFile); // NotSupportedException on FAT32\n// after\nvar drive = new DriveInfo(Path.GetPathRoot(existingFile));\nif (string.Equals(drive.DriveFormat, \"NTFS\", StringComparison.OrdinalIgnoreCase))\n    File.CreateHardlink(linkPath, existingFile);\nelse\n    File.Copy(existingFile, linkPath);","handlingStrategy":"try-catch","validationCode":"static bool SupportsHardLinks(string path)\n{\n    var root = Path.GetPathRoot(Path.GetFullPath(path));\n    var drive = new DriveInfo(root);\n    return string.Equals(drive.DriveFormat, \"NTFS\", StringComparison.OrdinalIgnoreCase)\n        || string.Equals(drive.DriveFormat, \"ReFS\", StringComparison.OrdinalIgnoreCase);\n}\n// only call File.CreateHardlink if SupportsHardLinks(existingFile) && SupportsHardLinks(linkPath)","typeGuard":"static bool CanCreateHardlink(string existing, string link) =>\n    SupportsHardLinks(existing) && SupportsHardLinks(link);","tryCatchPattern":"try { File.CreateHardlink(linkPath, existingFile); }\ncatch (NotSupportedException)\n{\n    // non-NTFS volume: fall back to a full copy\n    File.Copy(existingFile, linkPath, false);\n}","preventionTips":["Check DriveInfo.DriveFormat for NTFS before creating hard links","Expect ERROR_INVALID_FUNCTION-style NotSupportedException on FAT32/exFAT removable media","Ensure both paths are on the same NTFS volume (hard links cannot span volumes)","Provide a copy fallback for environments with diverse filesystem types"],"tags":["filesystem","hardlink","ntfs","notsupportedexception"],"backgroundTag":"hardlink-not-supported-filesystem","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}