public static extern bool BackupRead(IntPtr hFile, ref WIN32_STREAM_ID pBuffer, int lBytes, ref int lRead, bool bAbort, bool bSecurity, ref IntPtr context);
Example #2
0
 public static extern bool BackupRead(IntPtr hFile, ref WIN32_STREAM_ID pBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, bool bAbort, bool bProcessSecurity, ref IntPtr lpContext);
Example #3
0
                public StreamInfo?GetNextInfo()
                {
                    uint bytesRead;

                    if (!BackupRead(
                            hFile: fileHandle,
                            lpBuffer: buffer,
                            nNumberOfBytesToRead: structureSize,
                            lpNumberOfBytesRead: out bytesRead,
                            bAbort: false,
                            bProcessSecurity: true,
                            context: ref this.context))
                    {
                        int error = Marshal.GetLastWin32Error();
                        throw GetIoExceptionForError(error);
                    }

                    // Exit if at the end
                    if (bytesRead == 0)
                    {
                        return(null);
                    }

                    WIN32_STREAM_ID streamId = (WIN32_STREAM_ID)Marshal.PtrToStructure(buffer.DangerousGetHandle(), typeof(WIN32_STREAM_ID));
                    string          name     = null;

                    if (streamId.dwStreamNameSize > 0)
                    {
                        buffer.EnsureByteCapacity(streamId.dwStreamNameSize);
                        if (!BackupRead(
                                hFile: fileHandle,
                                lpBuffer: buffer,
                                nNumberOfBytesToRead: streamId.dwStreamNameSize,
                                lpNumberOfBytesRead: out bytesRead,
                                bAbort: false,
                                bProcessSecurity: true,
                                context: ref this.context))
                        {
                            int error = Marshal.GetLastWin32Error();
                            throw GetIoExceptionForError(error);
                        }
                        name = Marshal.PtrToStringUni(buffer.DangerousGetHandle(), (int)bytesRead / 2);
                    }

                    if (streamId.Size > 0)
                    {
                        // Move to the next header, if any
                        uint low, high;
                        if (!BackupSeek(
                                hFile: fileHandle,
                                dwLowBytesToSeek: uint.MaxValue,
                                dwHighBytesToSeek: int.MaxValue,
                                lpdwLowByteSeeked: out low,
                                lpdwHighByteSeeked: out high,
                                context: ref context))
                        {
                            int error = Marshal.GetLastWin32Error();
                            if (error != WinError.ERROR_SEEK)
                            {
                                throw GetIoExceptionForError(error);
                            }
                        }
                    }

                    return(new StreamInfo
                    {
                        Name = name,
                        Type = streamId.dwStreamId,
                        Size = streamId.Size
                    });
                }
Example #4
0
 public static extern bool BackupRead(SafeFileHandle hFile, ref WIN32_STREAM_ID pBuffer, uint lBytes, ref uint lRead,
                                      bool bAbort, bool bSecurity, ref IntPtr context);
Example #5
0
 public static extern bool BackupRead(IntPtr hFile, ref WIN32_STREAM_ID pBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, bool bAbort, bool bProcessSecurity, ref IntPtr lpContext);
Example #6
0
 [DllImport("kernel32")] public static extern bool BackupRead(IntPtr hFile, ref WIN32_STREAM_ID pBuffer, int lBytes, ref int lRead, bool bAbort, bool bSecurity, ref int Context);
 public static extern bool BackupRead(IntPtr hFile, ref WIN32_STREAM_ID pBuffer, int lBytes, ref int lRead, bool bAbort, bool bSecurity, ref IntPtr context);
Example #8
0
        public BackupStreamInformation?GetNextInfo()
        {
            uint bytesRead;

            if (!BackupDesktopMethods.Direct.BackupRead(
                    hFile: _fileHandle,
                    lpBuffer: _buffer,
                    nNumberOfBytesToRead: WIN32_STREAM_ID_SIZE,
                    lpNumberOfBytesRead: out bytesRead,
                    bAbort: false,
                    bProcessSecurity: true,
                    context: ref _context))
            {
                throw ErrorHelper.GetIoExceptionForLastError();
            }

            // Exit if at the end
            if (bytesRead == 0)
            {
                return(null);
            }

            WIN32_STREAM_ID streamId = Marshal.PtrToStructure <WIN32_STREAM_ID>(_buffer.DangerousGetHandle());
            string          name     = null;

            if (streamId.dwStreamNameSize > 0)
            {
                _buffer.EnsureByteCapacity(streamId.dwStreamNameSize);
                if (!BackupDesktopMethods.Direct.BackupRead(
                        hFile: _fileHandle,
                        lpBuffer: _buffer,
                        nNumberOfBytesToRead: streamId.dwStreamNameSize,
                        lpNumberOfBytesRead: out bytesRead,
                        bAbort: false,
                        bProcessSecurity: true,
                        context: ref _context))
                {
                    throw ErrorHelper.GetIoExceptionForLastError();
                }
                name = Marshal.PtrToStringUni(_buffer.DangerousGetHandle(), (int)bytesRead / 2);
            }

            if (streamId.Size > 0)
            {
                // Move to the next header, if any
                uint low, high;
                if (!BackupDesktopMethods.Direct.BackupSeek(
                        hFile: _fileHandle,
                        dwLowBytesToSeek: uint.MaxValue,
                        dwHighBytesToSeek: int.MaxValue,
                        lpdwLowByteSeeked: out low,
                        lpdwHighByteSeeked: out high,
                        context: ref _context))
                {
                    WindowsError error = ErrorHelper.GetLastError();
                    if (error != WindowsError.ERROR_SEEK)
                    {
                        throw ErrorHelper.GetIoExceptionForError(error);
                    }
                }
            }

            return(new BackupStreamInformation
            {
                Name = name,
                StreamType = streamId.dwStreamId,
                Size = streamId.Size
            });
        }