question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NTFS on non-Windows systems.

See original GitHub issue

Much of your NTFS implementation relies on RawSecurityDescriptor and SecurityIdentifier.

This is not supported on some non-windows CLR environments (.NET Core App 2), it infact throws an exception:

public RawSecurityDescriptor(byte[] binaryForm, int offset)
{
    throw new PlatformNotSupportedException(SR.PlatformNotSupported_AccessControl);
}

This includes when you perform Null checks.

public sealed class SecurityIdentifier : IdentityReference, IComparable<SecurityIdentifier>
{
...
    public static bool operator ==(SecurityIdentifier left, SecurityIdentifier right)
    {
      throw new PlatformNotSupportedException(SR.PlatformNotSupported_Principal);
    }
...
}

I have some code written to allow you to determine if this is available at runtime:

private static bool? _HasRawSecurityDescriptors;

public static bool HasRawSecurityDescriptors
{
	get 
	{
		if (_HasRawSecurityDescriptors == null)
		{
			try
			{
				// The `if` will throw if we do not support this functionality 
				// at runtime.
				SecurityIdentifier willThrowIfNoPolicyFramework = null;
				// ReSharper disable once ConditionIsAlwaysTrueOrFalse
				if (willThrowIfNoPolicyFramework == null) {}
				_HasRawSecurityDescriptors = true;
			}
			catch (PlatformNotSupportedException ex)
			{
				_HasRawSecurityDescriptors = false;
			}
		}

		return _HasRawSecurityDescriptors ?? false;
	}
}

It would be nice to be able to create NTFS volumes on other systems without relying on native support that doesn’t exist outside of the Windows CLR.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
grmartincommented, May 10, 2019

Whats fascinating is this code partially works on Mono… but .NET Core explicitly throws.

Mono

Gaius:DiscUtils grmartin$ csharp -e "System.Security.Principal.WindowsIdentity.GetCurrent().Token"
501

.NET Core

Unhandled Exception: System.TypeInitializationException: The type initializer for '<StartupCode$MacTestApp>.$Program' threw an exception. ---> System.PlatformNotSupportedException: Windows Principal functionality is not supported on this platform
0reactions
vddCorecommented, Jul 30, 2021

I did it some time ago, then forgot about it. Feel free to backport whatever, it’s all taken from Mono project anyway.

https://github.com/Ciastex/DiscUtils/commit/cf64cfc4a05763e1ebe655da6e05b7a7993ef246

Read more comments on GitHub >

github_iconTop Results From Across the Web

NTFS overview
NTFS, the primary file system for recent versions of Windows and Windows Server, provides a full set of features including security descriptors, ...
Read more >
NTFS
New Technology File System (NTFS) is a proprietary journaling file system developed by Microsoft. Starting with Windows NT 3.1, it is the default...
Read more >
How can I fix an inconsistent NTFS file system without ...
If the computer has nothing but Linux, you should not be using NTFS. There are no good Linux tools for repairing NTFS damage....
Read more >
NTFS: What is new technology file system, and how does it ...
NTFS is used by removable storage devices and Microsoft Windows to name, organize and store files. NT file system can encrypt or decrypt...
Read more >
What Is NTFS and How Does It Work?
NT file system (NTFS), which is also sometimes called the New Technology File System, is a process that the Windows NT operating system...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found