Replace non-WMI filesystem compression implemented in b31efb95
BinToss opened this issue · 5 comments
We'll use P/Invoke (built-in P/Invoke, dotnet/PInvoke, and/or CsWin32) to leverage DeviceIoControl for compression operations.
A FLOSS implementation such as DiscUtils is preferable, but there's a much higher risk disk error due to of developer-error.
Like many other file system utilities, it does not provide SetCompression methods or something similar. However, it provides everything needed to write this method.
This may also bypass file/directory handles.
The PR to close this issue is being held up by #232 which will be resolved by CodeDead/deadlock-dotnet-sdk
b31efb9
I hope this works the way I think it does.
I'm worried the attribute will be set without the file being compressed.
https://docs.microsoft.com/en-us/dotnet/api/system.io.fileattributes?view=net-6.0#remarks
It is not possible to change the compression status of a File object by using the File.SetAttributes method
Current Options
Traditional P/Invoke
pinvoke.net
PITA. Prefer the other two options.
P/Invoke and Win32 NuGet packages
github:dotnet/pinvoke
https://www.nuget.org/profiles/PInvoke
Most of what I'll use is in PInvoke.Kernel32
P/Invoke and Win32 code generation
github:microsoft/CsWin32
Produces smaller assemblies than PInvoke packages (when not using Trim).
Useful links
[GitHub] dotnet/pinvoke/tree/main/src/Kernel32
[MSDocs] Address-of operator &
[MSDocs] Compression Attribute
[MSDocs] Compression State
[MSDocs] CreateFileA function (fileapi.h)
[MSDocs] DeviceIoControl function (ioapiset.h)
[MSDocs] Directory Handles
[MSDocs] File Management Control Codes
[MSDocs] FSCTL_GET_COMPRESSION
[MSDocs] FSCTL_SET_COMPRESSION
[MSDocs] How to get information about files, folders, and drives (C# Programming Guide)
[MSDocs] Microsoft.Win32.SafeHandles Namespace
[MSDocs] Microsoft.Win32.SafeFileHandle Class
[MSDocs] Directory Handles
[MSDocs] System.IO.Directory Class
[MSDocs] System.IO.File.Open(String, FileStreamOptions) Method
[MSDocs] System.IO.FileStream.SafeFileHandle Property
[MSDocs] UnlockFile function (fileapi.h)
[MSDocs] UnlockFileEx function (fileapi.h)
[NuGet] Microsoft.Windows.CsWin32
[SO] How to get directory file handle in C#?
[SO] Open Directory Using CreateFile
[SO] What is SafeFileHandle in C# and when should I use it?
DeviceIoControl sucks. It should be broken down into dozens if not hundreds of specific functions. Telling it what to do via const/enums is terrible for documentation. Some parameters aren't used or need to be passed slightly differently depending on the operation code you use.
I've lost count of how many times I rewritten the function call simply because I don't know what the operation needs from the parameters.
Does it expect a pointer of a specific type here?
Is it safe to cast SafeHandle to SafeObjectHandle?
Is it safe to case short*
to void*
?
Why do the PInvoke NuGet packages lack IOCTL constants?
Why is OmniSharp unable to use the code generated by CsWin32?
Why can't I do sizeof(typeof((short) variable))
?
What was lost has been replaced...