/* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov * * 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 Microsoft.Win32.SafeHandles; using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Security; namespace Alphaleonis.Win32.Filesystem { internal static partial class NativeMethods { /// The BackupRead function can be used to back up a file or directory, including the security information. /// The function reads data associated with a specified file or directory into a buffer, /// which can then be written to the backup medium using the WriteFile function. /// /// /// This function is not intended for use in backing up files encrypted under the Encrypted File System. /// Use ReadEncryptedFileRaw for that purpose. /// Minimum supported client: Windows XP [desktop apps only] /// Minimum supported server: Windows Server 2003 [desktop apps only] /// /// The file. /// The buffer. /// Number of bytes to reads. /// [out] Number of bytes reads. /// true to abort. /// true to process security. /// [out] The context. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero, indicating that an I/O error occurred. To get extended error information, /// call GetLastError. /// [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool BackupRead(SafeFileHandle hFile, SafeGlobalMemoryBufferHandle lpBuffer, [MarshalAs(UnmanagedType.U4)] uint nNumberOfBytesToRead, [MarshalAs(UnmanagedType.U4)] out uint lpNumberOfBytesRead, [MarshalAs(UnmanagedType.Bool)] bool bAbort, [MarshalAs(UnmanagedType.Bool)] bool bProcessSecurity, ref IntPtr lpContext); /// The BackupSeek function seeks forward in a data stream initially accessed by using the or /// function. /// The function reads data associated with a specified file or directory into a buffer, which can then be written to the backup /// medium using the WriteFile function. /// /// /// Applications use the BackupSeek function to skip portions of a data stream that cause errors. /// This function does not seek across stream headers. For example, this function cannot be used to skip the stream name. /// If an application attempts to seek past the end of a substream, the function fails, the lpdwLowByteSeeked and /// lpdwHighByteSeeked parameters /// indicate the actual number of bytes the function seeks, and the file position is placed at the start of the next stream /// header. ///   /// Minimum supported client: Windows XP [desktop apps only] /// Minimum supported server: Windows Server 2003 [desktop apps only] /// /// The file. /// The low bytes to seek. /// The high bytes to seek. /// [out] The lpdw low bytes seeked. /// [out] The lpdw high bytes seeked. /// [out] The context. /// /// If the function could seek the requested amount, the function returns a nonzero value. /// If the function could not seek the requested amount, the function returns zero. To get extended error information, call /// GetLastError. /// [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool BackupSeek(SafeFileHandle hFile, [MarshalAs(UnmanagedType.U4)] uint dwLowBytesToSeek, [MarshalAs(UnmanagedType.U4)] uint dwHighBytesToSeek, [MarshalAs(UnmanagedType.U4)] out uint lpdwLowBytesSeeked, [MarshalAs(UnmanagedType.U4)] out uint lpdwHighBytesSeeked, ref IntPtr lpContext); /// The BackupWrite function can be used to restore a file or directory that was backed up using . /// Use the ReadFile function to get a stream of data from the backup medium, then use BackupWrite to write the data to the /// specified file or directory. ///   /// /// /// This function is not intended for use in restoring files encrypted under the Encrypted File System. Use WriteEncryptedFileRaw /// for that purpose. /// Minimum supported client: Windows XP [desktop apps only] /// Minimum supported server: Windows Server 2003 [desktop apps only] /// /// The file. /// The buffer. /// Number of bytes to writes. /// [out] Number of bytes writtens. /// true to abort. /// true to process security. /// [out] The context. /// /// If the function succeeds, the return value is nonzero. /// If the function fails, the return value is zero, indicating that an I/O error occurred. To get extended error information, /// call GetLastError. /// [SuppressMessage("Microsoft.Security", "CA5122:PInvokesShouldNotBeSafeCriticalFxCopRule")] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool BackupWrite(SafeFileHandle hFile, SafeGlobalMemoryBufferHandle lpBuffer, [MarshalAs(UnmanagedType.U4)] uint nNumberOfBytesToWrite, [MarshalAs(UnmanagedType.U4)] out uint lpNumberOfBytesWritten, [MarshalAs(UnmanagedType.Bool)] bool bAbort, [MarshalAs(UnmanagedType.Bool)] bool bProcessSecurity, ref IntPtr lpContext); } }