public BackupStreamInfo ReadStreamInfo() { using (SafeGlobalMemoryBufferHandle hBuf = new SafeGlobalMemoryBufferHandle(Marshal.SizeOf(typeof(NativeMethods.WIN32_STREAM_ID)))) { uint numberOfBytesRead; if (!NativeMethods.BackupRead(mFileHandle, hBuf, (uint)Marshal.SizeOf(typeof(NativeMethods.WIN32_STREAM_ID)), out numberOfBytesRead, false, mProcessSecurity, ref mContext)) { NativeError.ThrowException(); } if (numberOfBytesRead == 0) { return(null); } if (numberOfBytesRead < Marshal.SizeOf(typeof(NativeMethods.WIN32_STREAM_ID))) { throw new System.IO.IOException(Resources.IncompleteHeaderRead); } NativeMethods.WIN32_STREAM_ID streamID = (NativeMethods.WIN32_STREAM_ID)Marshal.PtrToStructure(hBuf.DangerousGetHandle(), typeof(NativeMethods.WIN32_STREAM_ID)); uint nameLength = (uint)Math.Min(streamID.dwStreamNameSize, hBuf.Capacity); if (!NativeMethods.BackupRead(mFileHandle, hBuf, nameLength, out numberOfBytesRead, false, mProcessSecurity, ref mContext)) { NativeError.ThrowException(); } string name = Marshal.PtrToStringUni(hBuf.DangerousGetHandle(), (int)nameLength / 2); return(new BackupStreamInfo(streamID, name)); } }
/// <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; }