示例#1
0
        public static void Main111(string[] args)
        {
            const string drive = "X:";

            // label
            var driveInfo = new DriveInfo(drive);

            driveInfo.VolumeLabel = DiskContent.VolumeLabel;

            // long contiguous file
            using (var fc = File.Create(Path.Combine(drive, DiskContent.LongContiguousFileName)))
            {
                for (ulong offset = 0; offset < DiskContent.LongFileSize; offset += sizeof(ulong))
                {
                    var b = LittleEndian.GetBytes(DiskContent.GetLongContiguousFileNameOffsetValue(offset));
                    fc.Write(b, 0, b.Length);
                }
            }

            // long sparse files
            const uint chunks = 1u << 10;

            for (ulong offsetBase = 0; offsetBase < DiskContent.LongFileSize; offsetBase += chunks)
            {
                using (var fs1 = File.OpenWrite(Path.Combine(drive, DiskContent.LongSparseFile1Name)))
                    using (var fs2 = File.OpenWrite(Path.Combine(drive, DiskContent.LongSparseFile2Name)))
                    {
                        fs1.Seek(0, SeekOrigin.End);
                        fs2.Seek(0, SeekOrigin.End);
                        for (ulong subOffset = 0; subOffset < chunks; subOffset += sizeof(ulong))
                        {
                            var offset = offsetBase + subOffset;
                            var b1     = LittleEndian.GetBytes(DiskContent.GetLongSparseFile1NameOffsetValue(offset));
                            fs1.Write(b1, 0, b1.Length);
                            var b2 = LittleEndian.GetBytes(DiskContent.GetLongSparseFile2NameOffsetValue(offset));
                            fs2.Write(b2, 0, b2.Length);
                        }
                    }
            }

            // An empty folder
            Directory.CreateDirectory(Path.Combine(drive, DiskContent.EmptyRootFolderFileName));

            // A folder full of garbage
            var longDirectoryPath = Path.Combine(drive, DiskContent.LongFolderFileName);

            Directory.CreateDirectory(longDirectoryPath);
            for (int subFileIndex = 0; subFileIndex < DiskContent.LongFolderEntriesCount; subFileIndex++)
            {
                var path = Path.Combine(longDirectoryPath, Guid.NewGuid().ToString("N"));
                using (var t = File.CreateText(path))
                {
                    t.WriteLine(subFileIndex);
                }
            }
        }
 public void ReadFile()
 {
     using (var testEnvironment = StreamTestEnvironment.FromExistingVhdx())
         using (var filesystem = new ExFatEntryFilesystem(testEnvironment.PartitionStream))
         {
             var file = filesystem.FindChild(filesystem.RootDirectory, DiskContent.LongContiguousFileName);
             var vb   = new byte[sizeof(ulong)];
             using (var stream = filesystem.OpenFile(file, FileAccess.Read))
             {
                 for (ulong offset = 0; offset < DiskContent.LongFileSize; offset += 8)
                 {
                     stream.Read(vb, 0, vb.Length);
                     var v = LittleEndian.ToUInt64(vb);
                     Assert.AreEqual(v, DiskContent.GetLongContiguousFileNameOffsetValue(offset));
                 }
             }
         }
 }
示例#3
0
 public void TruncateFileTest()
 {
     using (var testEnvironment = StreamTestEnvironment.FromExistingVhdx(true))
     {
         using (var filesystem = new ExFatEntryFilesystem(testEnvironment.PartitionStream))
         {
             var f = filesystem.FindChild(filesystem.RootDirectory, DiskContent.LongContiguousFileName);
             using (var s = filesystem.OpenFile(f, FileAccess.ReadWrite))
             {
                 s.SetLength(16);
                 s.Seek(0, SeekOrigin.Begin);
                 var b = new byte[8];
                 Assert.AreEqual(8, s.Read(b, 0, b.Length));
                 Assert.AreEqual(DiskContent.GetLongContiguousFileNameOffsetValue(0), LittleEndian.ToUInt64(b));
                 Assert.AreEqual(8, s.Read(b, 0, b.Length));
                 Assert.AreEqual(DiskContent.GetLongContiguousFileNameOffsetValue(8), LittleEndian.ToUInt64(b));
                 Assert.AreEqual(0, s.Read(b, 0, b.Length));
             }
         }
     }
 }