diff --git a/Claunia.IO/ChangeLog b/Claunia.IO/ChangeLog index e64b170..e49c4a1 100644 --- a/Claunia.IO/ChangeLog +++ b/Claunia.IO/ChangeLog @@ -1,3 +1,13 @@ +2015-05-04 Natalia Portillo + + * Claunia.IO.csproj: + * Interop/Windows/Interop.Windows.EAs.cs: + Implement callings for Extended Attributes on NT. + + * Interop/Windows/Interop.Windows.Errors.cs: + * Interop/Windows/Interop.Windows.Libraries.cs: + Typo. + 2015-05-04 Natalia Portillo * Claunia.IO.csproj: diff --git a/Claunia.IO/Claunia.IO.csproj b/Claunia.IO/Claunia.IO.csproj index f023a8a..29c2dad 100644 --- a/Claunia.IO/Claunia.IO.csproj +++ b/Claunia.IO/Claunia.IO.csproj @@ -69,6 +69,7 @@ + diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.EAs.cs b/Claunia.IO/Interop/Windows/Interop.Windows.EAs.cs new file mode 100644 index 0000000..0b45033 --- /dev/null +++ b/Claunia.IO/Interop/Windows/Interop.Windows.EAs.cs @@ -0,0 +1,132 @@ +// +// Interop.Windows.EAs.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2015 © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software", to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System.Runtime.InteropServices; +using System; + +internal static partial class Interop +{ + internal static partial class Windows + { + /// + /// Status of a I/O call + /// + public struct IO_STATUS_BLOCK + { + /// + /// This is the completion status, either if the requested operation was completed successfully or an informational, warning, or error STATUS_XXX value. For more information, . + /// + public NTSTATUS status; + /// + /// This is set to a request-dependent value. For example, on successful completion of a transfer request, this is set to the number of bytes transferred. If a transfer request is completed with another STATUS_XXX, this member is set to zero. + /// + public ulong information; + } + + const byte FILE_NEED_EA = 0x80; + + /// + /// The FILE_FULL_EA_INFORMATION structure provides extended attribute (EA) information. + /// + public struct FILE_FULL_EA_INFORMATION + { + /// + /// The offset of the next -type entry. This member is zero if no other entries follow this one. + /// + public ulong NextEntryOffset; + /// + /// Can be zero or can be set with , indicating that the file to which the EA belongs cannot be interpreted without understanding the associated extended attributes. + /// + public byte Flags; + /// + /// The length in bytes of the array. This value does not include a null-terminator to . + /// + public byte EaNameLength; + /// + /// The length in bytes of each EA value in the array. + /// + public ushort EaValueLength; + /// + /// An array of characters naming the EA for this entry. + /// + public byte[] EaName; + } + + /// + /// The FILE_GET_EA_INFORMATION structure is used to query for extended-attribute (EA) information. + /// + struct FILE_GET_EA_INFORMATION + { + /// + /// Offset, in bytes, of the next -typed entry. This member is zero if no other entries follow this one. + /// + public ulong NextEntryOffset; + /// + /// Length, in bytes, of the EaName array. This value does not include a NULL terminator. + /// + public byte EaNameLength; + /// + /// Specifies the first character of the name of the extended attribute to be queried. This is followed in memory by the remainder of the string. + /// + public byte[] EaName; + } + + /// + /// Returns information about extended-attribute (EA) values for a file + /// + /// Returns or an appropriate value such as the following. + /// : The file system does not support extended attributes. + /// : The NtQueryEaFile routine encountered a pool allocation failure. + /// : The EaList parameter is not formatted correctly. + /// + /// The handle for the file on which the operation is to be performed. + /// A pointer to an structure that receives the final completion status and other information about the requested operation. + /// A pointer to a caller-supplied -structured output buffer, where the extended attribute values are to be returned. + /// The length, in bytes, of the buffer that the Buffer parameter points to. + /// Set to true if NtQueryEaFile should return only the first entry that is found. + /// A pointer to a caller-supplied -structured input buffer, which specifies the extended attributes to be queried. This parameter is optional and can be null. + /// The length, in bytes, of the buffer that the EaList parameter points to. + /// The index of the entry at which scanning the file's extended-attribute list should begin. This parameter is ignored if the EaList parameter points to a nonempty list. This parameter is optional and can be null. + /// Set to true if NtQueryEaFile should begin the scan at the first entry in the file's extended-attribute list. If this parameter is set to false, the routine resumes the scan from a previous call to ZwQueryEaFile. + [DllImport(Libraries.NTDLL)] + public static extern NTSTATUS NtQueryEaFile(IntPtr FileHandle, + ref IO_STATUS_BLOCK IoStatusBlock, IntPtr Buffer, ulong Length, + bool ReturnSingleEntry, IntPtr EaList, UInt32 EaListLength, ref UInt32 EaIndex, + UInt32 RestartScan); + /// + /// Sets extended-attribute (EA) values for a file. + /// + /// Returns STATUS_SUCCESS or an appropriate NTSTATUS value such as the following: + /// : The EaList parameter is not formatted correctly. + /// + /// The handle for the file on which the operation is to be performed. + /// A pointer to an structure that receives the final completion status and other information about the requested operation. + /// A pointer to a caller-supplied, -structured input buffer that contains the extended attribute values to be set. + /// Length, in bytes, of the buffer that the Buffer parameter points to. + [DllImport(Libraries.NTDLL)] + public static extern NTSTATUS NtSetEaFile(IntPtr FileHandle, ref IO_STATUS_BLOCK IoStatusBlock, IntPtr Buffer, UInt32 Length); + } +} + diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.Errors.cs b/Claunia.IO/Interop/Windows/Interop.Windows.Errors.cs index 18bfa04..4698134 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.Errors.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.Errors.cs @@ -1,5 +1,5 @@ // -// Interop.Windows.types.cs +// Interop.Windows.Errors.cs // // Author: // Natalia Portillo @@ -30,7 +30,7 @@ internal static partial class Interop { internal static partial class Windows { - enum NTSTATUS : UInt32 + public enum NTSTATUS : UInt32 { /// /// The operation completed successfully. diff --git a/Claunia.IO/Interop/Windows/Interop.Windows.Libraries.cs b/Claunia.IO/Interop/Windows/Interop.Windows.Libraries.cs index ef3900f..2fecff4 100644 --- a/Claunia.IO/Interop/Windows/Interop.Windows.Libraries.cs +++ b/Claunia.IO/Interop/Windows/Interop.Windows.Libraries.cs @@ -1,5 +1,5 @@ // -// Interop.Linux.Libraries.cs +// Interop.Windows.Libraries.cs // // Author: // Natalia Portillo