Skip to content

Commit 3ae6a77

Browse files
committed
Add support for viewing NTFS partition contents
1 parent 53e27d0 commit 3ae6a77

File tree

6 files changed

+213
-44
lines changed

6 files changed

+213
-44
lines changed

XvdTool.Streaming/HttpFileStream.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Diagnostics;
2-
using System.Net;
32
using System.Net.Http.Headers;
4-
using System;
53

64
namespace XvdTool.Streaming;
75

XvdTool.Streaming/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ internal abstract class XvdCommand<T> : Command<T> where T : XvdCommandSettings
6161
{
6262
protected StreamedXvdFile XvdFile = default!;
6363

64-
protected void Initialize(XvdCommandSettings settings)
64+
protected void Initialize(XvdCommandSettings settings, bool requiresWriting)
6565
{
6666
Debug.Assert(settings.XvcPath != null, "settings.XvcPath != null");
6767

6868
var path = settings.XvcPath;
6969

7070
XvdFile = path.StartsWith("http")
7171
? StreamedXvdFile.OpenFromUrl(path)
72-
: StreamedXvdFile.OpenFromFile(path);
72+
: StreamedXvdFile.OpenFromFile(path, requiresWriting);
7373

7474
XvdFile.Parse();
7575
}
@@ -89,7 +89,7 @@ internal abstract class CryptoCommand<T> : XvdCommand<T> where T : CryptoCommand
8989

9090
protected bool Initialize(CryptoCommandSettings settings, out KeyEntry entry)
9191
{
92-
base.Initialize(settings);
92+
base.Initialize(settings, requiresWriting: true);
9393

9494
Debug.Assert(XvdFile != null, "XvdFile != null");
9595

@@ -158,7 +158,7 @@ public sealed class Settings : XvdCommandSettings
158158

159159
public override int Execute(CommandContext context, Settings settings)
160160
{
161-
Initialize(settings);
161+
Initialize(settings, requiresWriting: false);
162162

163163
Debug.Assert(XvdFile != null, "XvdFile != null");
164164

@@ -241,7 +241,7 @@ public sealed class Settings : XvdCommandSettings;
241241

242242
public override int Execute(CommandContext context, Settings settings)
243243
{
244-
Initialize(settings);
244+
Initialize(settings, requiresWriting: false);
245245

246246
Debug.Assert(XvdFile != null, "XvdFile != null");
247247

XvdTool.Streaming/StreamedXvdFile.LocalImpl.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ private void LocalDecryptData(in KeyEntry key, bool recalculateHashes)
118118
{
119119
// TODO
120120
}
121-
122-
memoryFile.Dispose();
123121
}
124122
// ReSharper restore AccessToDisposedClosure
125123

@@ -155,8 +153,7 @@ private void LocalDecryptSection(ProgressTask progressTask, MemoryMappedFile mem
155153

156154
using var directAccessor = memoryFile.CreateDirectAccessor(
157155
(long)(offset + mappedPageOffset * XvdFile.PAGE_SIZE),
158-
(long)pageCountThisOffset * XvdFile.PAGE_SIZE,
159-
MemoryMappedFileAccess.ReadWrite);
156+
(long)pageCountThisOffset * XvdFile.PAGE_SIZE);
160157

161158
for (uint i = 0; i < pageCountThisOffset; i++)
162159
{
@@ -195,14 +192,13 @@ private Span<uint> CacheDataUnits(ulong startPage, ulong count)
195192

196193
_stream.Position = hashPageOffset;
197194

198-
int read;
199195
for (ulong i = 0; i < count; i++)
200196
{
201197
if (refreshCache)
202198
{
203199
refreshCache = false;
204200

205-
read = _stream.Read(pageCache);
201+
var read = _stream.Read(pageCache);
206202
Debug.Assert(read == pageCache.Length, "read == pageCache.Length");
207203
}
208204

@@ -269,11 +265,11 @@ private bool LocalVerifyDataHashesTask(ProgressContext ctx)
269265

270266
var task = ctx.AddTask("Verifying hashes", maxValue: (long) dataBlockCount * (int) XvdFile.PAGE_SIZE);
271267

272-
int read;
273268
for (ulong i = 0; i < dataBlockCount; i++)
274269
{
275270
task.Increment(XvdFile.PAGE_SIZE);
276271

272+
int read;
277273
if (refreshCache)
278274
{
279275
refreshCache = false;

0 commit comments

Comments
 (0)