Example #1
0
        public BackupStreamInfo ReadStreamInfo()
        {
            using (SafeGlobalMemoryBufferHandle hBuf = new SafeGlobalMemoryBufferHandle(Marshal.SizeOf(typeof(NativeMethods.WIN32_STREAM_ID))))
            {
                uint numberOfBytesRead;
                if (!NativeMethods.BackupRead(_safeFileHandle, hBuf, (uint)Marshal.SizeOf(typeof(NativeMethods.WIN32_STREAM_ID)), out numberOfBytesRead, false, mProcessSecurity, ref m_context))
                {
                    NativeError.ThrowException();
                }

                if (numberOfBytesRead == 0)
                {
                    return(null);
                }

                if (numberOfBytesRead < Marshal.SizeOf(typeof(NativeMethods.WIN32_STREAM_ID)))
                {
                    throw new IOException(Resources.IncompleteHeaderRead);
                }

                NativeMethods.WIN32_STREAM_ID streamID = hBuf.PtrToStructure <NativeMethods.WIN32_STREAM_ID>();

                uint nameLength = (uint)Math.Min(streamID.StreamNameSize, hBuf.Capacity);
                if (!NativeMethods.BackupRead(_safeFileHandle, hBuf, nameLength, out numberOfBytesRead, false, mProcessSecurity, ref m_context))
                {
                    NativeError.ThrowException();
                }

                string name = hBuf.PtrToStringUni((int)nameLength / 2);

                return(new BackupStreamInfo(streamID, name));
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BackupStreamInfo"/> class.
 /// </summary>
 /// <param name="streamID">The stream ID.</param>
 /// <param name="name">The name.</param>
 internal BackupStreamInfo(NativeMethods.WIN32_STREAM_ID streamID, string name)
 {
     mSize       = (long)streamID.Size;
     mName       = name;
     mAttributes = (StreamAttributes)streamID.dwStreamAttributes;
     mStreamType = (BackupStreamType)streamID.dwStreamId;
 }