Пример #1
0
        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            var entry = new DataBlock(data);

            byte first = entry.GetByte(offset + Entry.DOSName);

            if (first == FileNameAttribute.LastEntry)
            {
                return(false);
            }

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
            {
                return(false);
            }

            if (first == FileNameAttribute.Escape)
            {
                return(false);
            }

            uint startcluster = FatFileSystem.GetClusterEntry(data, offset, type);

            if (startcluster == cluster)
            {
                return(true);
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Compares the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public bool Compare(byte[] data, uint offset, FatType type)
        {
            BinaryFormat entry = new BinaryFormat(data);

            byte first = entry.GetByte(offset + Entry.DOSName);

            if (first == FileNameAttribute.LastEntry)
            {
                return(false);
            }

            if ((first == FileNameAttribute.Deleted) | (first == FileNameAttribute.Dot))
            {
                return(false);
            }

            if (first == FileNameAttribute.Escape)
            {
                return(false);
            }

            string entryname = FatFileSystem.ExtractFileName(data, offset);

            if (entryname == name)
            {
                return(true);
            }

            return(false);
        }
Пример #3
0
 public FatDirectory(FatFileSystem aFileSystem, string aName, ulong firstCluster, Directory baseDirectory, ulong size)
     : base(aFileSystem, aName, baseDirectory)
 {
     FileSystem = aFileSystem;
     FirstClusterNum = firstCluster;
     Size = size;
 }
Пример #4
0
        public static DiscFileSystem FormatStream(string fileSystemName, Stream stream, long size, string label)
        {
            switch (fileSystemName)
            {
            case "NTFS":
            {
                var geometry = FindBasicGeometry(stream, size);

                Logger.Info("Formatting stream as NTFS");
                return(NtfsFileSystem.Format(stream, label, geometry, 0, geometry.TotalSectorsLong));
            }

            case "FAT":
            {
                var geometry = FindBasicGeometry(stream, size);

                Logger.Info("Formatting stream as FAT");
#pragma warning disable CS0618 // Typ oder Element ist veraltet
                return(FatFileSystem.FormatPartition(stream, label, geometry, 0, geometry.TotalSectors, 0));

#pragma warning restore CS0618 // Typ oder Element ist veraltet
            }

            default:
            {
                Logger.Error("Requested file system is not supported (Requested {0}, supported: NTFS, FAT)",
                             fileSystemName);
                Environment.Exit(1);
                break;
            }
            }

            return(null);
        }
Пример #5
0
        internal ClusterStream(FatFileSystem fileSystem, FileAccess access, uint firstCluster, uint length)
        {
            _access = access;
            _reader = fileSystem.ClusterReader;
            _fat    = fileSystem.Fat;
            _length = length;

            _knownClusters = new List <uint>();
            if (firstCluster != 0)
            {
                _knownClusters.Add(firstCluster);
            }
            else
            {
                _knownClusters.Add(FatBuffer.EndOfChain);
            }

            if (_length == uint.MaxValue)
            {
                _length = DetectLength();
            }

            _currentCluster = uint.MaxValue;
            _clusterBuffer  = new byte[_reader.ClusterSize];
        }
Пример #6
0
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            ulong aFirstCluster)
            : base(aFileSystem, aParent, aName, 0, DirectoryEntryTypeEnum.Directory)
        {
            if (aFileSystem == null)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aFileSystem is null.");
                throw new ArgumentNullException(nameof(aFileSystem));
            }

            if (aName == null)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aName is null.");
                throw new ArgumentNullException(nameof(aName));
            }

            if (aFirstCluster < 2)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aParent.Name = {aParent?.mName}, aName = {aName}, aFirstCluster = {aFirstCluster}");

            mFileSystem = aFileSystem;
            mParent = aParent;
            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = 0;
        }
Пример #7
0
        /// <summary>
        /// This method creates a .vhd hard drive formatted in FAT.
        /// </summary>
        /// <param name="diskSize">The size of the disk in bytes.</param>
        /// <param name="location">Defines the physical location and file name. .vhd extension required.</param>
        /// <param name="dynamic">Determines whether or not the disk will be of fixed size or dynamic size.</param>
        /// <returns>A bool determining if the method succeeded.</returns>
        public bool CreateFatDrive(long diskSize, string location, bool dynamic)
        {
            try {
                using (Stream vhdStream = File.Create(@location))
                {
                    Disk disk = null;

                    if (dynamic)
                    {
                        disk = Disk.InitializeDynamic(vhdStream, Ownership.None, diskSize);
                    }
                    else
                    {
                        disk = Disk.InitializeFixed(vhdStream, Ownership.None, diskSize);
                    }

                    BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsFat);
                    FatFileSystem.FormatPartition(disk, 0, null);

                    return(true);
                }
            }
            catch (IOException e)
            {
                Console.WriteLine(e.StackTrace);
                return(false);
            }
        }
Пример #8
0
        public void HonoursReadOnly()
        {
            SparseMemoryStream diskStream = new SparseMemoryStream();
            FatFileSystem      fs         = FatFileSystem.FormatFloppy(diskStream, FloppyDiskType.HighDensity, "FLOPPY_IMG ");

            fs.CreateDirectory(@"AAA");
            fs.CreateDirectory(@"BAR");
            using (Stream t = fs.OpenFile(@"BAR\AAA.TXT", FileMode.Create, FileAccess.ReadWrite)) { }
            using (Stream s = fs.OpenFile(@"BAR\FOO.TXT", FileMode.Create, FileAccess.ReadWrite))
            {
                StreamWriter w = new StreamWriter(s);
                w.WriteLine("FOO - some sample text");
                w.Flush();
            }
            fs.SetLastAccessTimeUtc(@"BAR", new DateTime(1980, 1, 1));
            fs.SetLastAccessTimeUtc(@"BAR\FOO.TXT", new DateTime(1980, 1, 1));

            // Check we can access a file without any errors
            SparseStream  roDiskStream = SparseStream.ReadOnly(diskStream, Ownership.None);
            FatFileSystem fatFs        = new FatFileSystem(roDiskStream);

            using (Stream fileStream = fatFs.OpenFile(@"BAR\FOO.TXT", FileMode.Open))
            {
                fileStream.ReadByte();
            }
        }
Пример #9
0
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            ulong aFirstCluster)
            : base(aFileSystem, aParent, aName, 0, DirectoryEntryTypeEnum.Directory)
        {
            if (aFileSystem == null)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aFileSystem is null.");
                throw new ArgumentNullException(nameof(aFileSystem));
            }

            if (aName == null)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aName is null.");
                throw new ArgumentNullException(nameof(aName));
            }

            if (aFirstCluster < 2)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aParent.Name =", aParent?.mName, ", aName =", aName, ", aFirstCluster =", aFirstCluster);

            mFileSystem            = aFileSystem;
            mParent                = aParent;
            mFirstClusterNum       = aFirstCluster;
            mEntryHeaderDataOffset = 0;
        }
Пример #10
0
        public void FileSystemInfo()
        {
            FatFileSystem      fs = FatFileSystem.FormatFloppy(new MemoryStream(), FloppyDiskType.HighDensity, "FLOPPY_IMG ");
            DiscFileSystemInfo fi = fs.GetFileSystemInfo(@"SOMEDIR\SOMEFILE");

            Assert.IsNotNull(fi);
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the Directory class.  Use this constructor to represent the root directory.
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="dirStream">The stream containing the directory info.</param>
        internal Directory(FatFileSystem fileSystem, Stream dirStream)
        {
            FileSystem = fileSystem;
            _dirStream = dirStream;

            LoadEntries();
        }
Пример #12
0
        public void ReadFatFilesystemTest(string path)
        {
            using (Stream developerDiskImageStream = File.OpenRead(path))
                using (var disk = new Disk(developerDiskImageStream, Ownership.None))
                {
                    // Find the first (and supposedly, only, FAT partition)
                    var volumes = VolumeManager.GetPhysicalVolumes(disk);
                    foreach (var volume in volumes)
                    {
                        var fileSystems = FileSystemManager.DetectFileSystems(volume);

                        var fileSystem = Assert.Single(fileSystems);
                        Assert.Equal("FAT", fileSystem.Name);

                        using (FatFileSystem fat = (FatFileSystem)fileSystem.Open(volume))
                        {
                            Assert.True(fat.FileExists("hello.txt"));

                            using (Stream helloStream = fat.OpenFile("hello.txt", FileMode.Open, FileAccess.Read))
                                using (MemoryStream copyStream = new MemoryStream())
                                {
                                    Assert.NotEqual(0, helloStream.Length);
                                    helloStream.CopyTo(copyStream);
                                    Assert.Equal(helloStream.Length, copyStream.Length);

                                    Assert.Equal("Hello, World!\n", Encoding.UTF8.GetString(copyStream.ToArray()));
                                }
                        }
                    }
                }
        }
Пример #13
0
 public FatDirectory(FatFileSystem aFileSystem, string aName, ulong firstCluster, Directory baseDirectory, ulong size)
     : base(aFileSystem, aName, baseDirectory)
 {
     FileSystem      = aFileSystem;
     FirstClusterNum = firstCluster;
     Size            = size;
 }
Пример #14
0
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            ulong aFirstCluster)
            : base(aFileSystem, aParent, aName, 0, DirectoryEntryTypeEnum.Directory)
        {
            if (aFileSystem == null)
            {
                throw new ArgumentNullException("aFileSystem");
            }

            if (aName == null)
            {
                throw new ArgumentNullException("aName");
            }

            if (aFirstCluster < 2)
            {
                throw new ArgumentOutOfRangeException("aFirstCluster");
            }

            mFileSystem = aFileSystem;
            mParent = aParent;
            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = 0;

            //FatHelpers.Debug(
            //    "-- FatDirectoryEntry.ctor : " + "aParent.Name = " + aParent?.mName + ", aName = " + aName
            //    + ", aFirstCluster = " + aFirstCluster + " --");
        }
Пример #15
0
        public void DirectoryInfo()
        {
            FatFileSystem     fs = FatFileSystem.FormatFloppy(new MemoryStream(), FloppyDiskType.HighDensity, "FLOPPY_IMG ");
            DiscDirectoryInfo fi = fs.GetDirectoryInfo(@"SOMEDIR");

            Assert.NotNull(fi);
        }
Пример #16
0
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            ulong aFirstCluster)
            : base(aFileSystem, aParent, aName, 0, DirectoryEntryTypeEnum.Directory)
        {
            if (aFileSystem == null)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aFileSystem is null.");
                throw new ArgumentNullException(nameof(aFileSystem));
            }

            if (aName == null)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aName is null.");
                throw new ArgumentNullException(nameof(aName));
            }

            if (aFirstCluster < 2)
            {
                FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            FileSystemHelpers.Debug("FatDirectoryEntry.ctor", "aParent.Name =", aParent?.mName, ", aName =", aName, ", aFirstCluster =", aFirstCluster);

            mFileSystem = aFileSystem;
            mParent = aParent;
            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = 0;
        }
Пример #17
0
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aName,
            ulong aFirstCluster)
            : base(aFileSystem, aParent, aName, 0, DirectoryEntryTypeEnum.Directory)
        {
            if (aFileSystem == null)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aFileSystem is null.");
                throw new ArgumentNullException(nameof(aFileSystem));
            }

            if (aName == null)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aName is null.");
                throw new ArgumentNullException(nameof(aName));
            }

            if (aFirstCluster < 2)
            {
                Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            Global.mFileSystemDebugger.SendInternal($"FatDirectoryEntry.ctor : aParent.Name = {aParent?.mName}, aName = {aName}, aFirstCluster = {aFirstCluster}");

            mFileSystem            = aFileSystem;
            mParent                = aParent;
            mFirstClusterNum       = aFirstCluster;
            mEntryHeaderDataOffset = 0;
        }
Пример #18
0
        public void Setup()
        {
            var xDevice    = new TestBlockDevice();
            var xPartition = new Partition(xDevice, 0, xDevice.BlockCount);
            var xFactory   = new FatFileSystemFactory();

            mFS = (FatFileSystem)xFactory.Create(xPartition, "0:\\", (long)(xPartition.BlockSize * xPartition.BlockCount));
        }
Пример #19
0
 // Size is UInt32 because FAT doesn't support bigger.
 // Don't change to UInt64
 public FatDirectoryEntry(FatFileSystem aFileSystem, FatDirectoryEntry aParent, string aName, uint aSize, ulong aFirstClusterNum, uint aEntryHeaderDataOffset, DirectoryEntryTypeEnum aEntryType)
     : base(aFileSystem, aParent, aName, aSize, aEntryType)
 {
     FileSystem = aFileSystem;
     Parent = aParent;
     FirstClusterNum = aFirstClusterNum;
     EntryHeaderDataOffset = aEntryHeaderDataOffset;
 }
Пример #20
0
        public FatFileSystemProvider OpenUserPartition()
        {
            IStorage encStorage = User.Open().AsStorage();
            var      decStorage = new CachedStorage(new Aes128XtsStorage(encStorage, Keyset.BisKeys[3], 0x4000, true), 0x4000, 4, true);
            var      fat        = new FatFileSystem(decStorage.AsStream(FileAccess.Read), Ownership.None);

            return(new FatFileSystemProvider(fat));
        }
Пример #21
0
        public static FileSystemType GetFileSystemType(Partition aDevice)
        {
            if (FatFileSystem.IsDeviceFAT(aDevice))
            {
                return(FileSystemType.FAT);
            }

            return(FileSystemType.Unknown);
        }
Пример #22
0
        public void Root()
        {
            FatFileSystem fs = FatFileSystem.FormatFloppy(new MemoryStream(), FloppyDiskType.HighDensity, "FLOPPY_IMG ");

            Assert.IsNotNull(fs.Root);
            Assert.IsTrue(fs.Root.Exists);
            Assert.IsEmpty(fs.Root.Name);
            Assert.IsNull(fs.Root.Parent);
        }
Пример #23
0
 private void CopyFileFromFs(string dstFile, string srcFile, FatFileSystem dstFat)
 {
     MakeDirectory(dstFile, dstFat);
     using (var dst = dstFat.OpenFile(dstFile, FileMode.Create)) {
         using (var src = File.OpenRead(srcFile)) {
             src.CopyTo(dst);
         }
     }
 }
Пример #24
0
        public void Label()
        {
            FatFileSystem fs = FatFileSystem.FormatFloppy(new MemoryStream(), FloppyDiskType.HighDensity, "FLOPPY_IMG ");

            Assert.AreEqual("FLOPPY_IMG ", fs.VolumeLabel);

            fs = FatFileSystem.FormatFloppy(new MemoryStream(), FloppyDiskType.HighDensity, null);
            Assert.AreEqual("NO NAME    ", fs.VolumeLabel);
        }
Пример #25
0
        public override FileSystemInfo[] Detect(Stream stream, VolumeInfo volume)
        {
            if (FatFileSystem.Detect(stream))
            {
                return(new FileSystemInfo[] { new VfsFileSystemInfo("FAT", "Microsoft FAT", Open) });
            }

            return(new FileSystemInfo[0]);
        }
Пример #26
0
        private void MakeDirectory(string fileName, FatFileSystem dstFat)
        {
            var dirname = Path.GetDirectoryName(fileName);

            if (dirname != @"\" && dirname != "" && !dstFat.DirectoryExists(dirname))
            {
                dstFat.CreateDirectory(dirname);
            }
        }
Пример #27
0
        public NandPartition OpenUserPartition()
        {
            SparseStream encStream = User.Open();
            Xts          xts       = XtsAes128.Create(Keyset.BisKeys[3]);
            var          decStream = new RandomAccessSectorStream(new XtsSectorStream(encStream, xts, 0x4000, 0), true);
            var          fat       = new FatFileSystem(decStream, Ownership.None);

            return(new NandPartition(fat));
        }
Пример #28
0
 private void CreateFile(PatchedFile file, FatFileSystem dstFat)
 {
     MakeDirectory(file.Name, dstFat);
     using (var dst = dstFat.OpenFile(file.Name, FileMode.Create)) {
         using (var ms = new MemoryStream(file.FileData)) {
             ms.Position = 0;
             ms.CopyTo(dst);
         }
     }
 }
Пример #29
0
        public void Setup()
        {
            DebuggerFactory.WriteToConsole = true;
            var xDevice    = new TestBlockDevice();
            var xPartition = new Partition(xDevice, 0, xDevice.BlockCount);
            var xFactory   = new FatFileSystemFactory();

            mFS  = (FatFileSystem)xFactory.Create(xPartition, "0:\\", (long)(xPartition.BlockSize * xPartition.BlockCount));
            mFat = mFS.GetFat(0);
        }
Пример #30
0
        public NandPartition OpenUserPartition()
        {
            IStorage encStorage = User.Open().AsStorage();
            var      decStorage = new CachedStorage(new Aes128XtsStorage(encStorage, Keyset.BisKeys[3], 0x4000, true), 0x4000, 4, true);

            decStorage.SetReadOnly();
            var fat = new FatFileSystem(decStorage.AsStream(), Ownership.None);

            return(new NandPartition(fat));
        }
Пример #31
0
        public FatFileStream(FatFileSystem fileSystem, Directory dir, long fileId, FileAccess access)
        {
            _dir   = dir;
            _dirId = fileId;

            DirectoryEntry dirEntry = _dir.GetEntry(_dirId);

            _stream = new ClusterStream(fileSystem, access, (uint)dirEntry.FirstCluster, (uint)dirEntry.FileSize);
            _stream.FirstClusterChanged += FirstClusterAllocatedHandler;
        }
Пример #32
0
        public void Read()
        {
            var path = @"d:\temp\mbr.img";

            DiscUtils.Containers.SetupHelper.SetupContainers();
            DiscUtils.FileSystems.SetupHelper.SetupFileSystems();
            var disk        = VirtualDisk.OpenDisk(path, FileAccess.ReadWrite);
            var fs          = new FatFileSystem(disk.Partitions[0].Open());
            var directories = fs.GetDirectories("");
            var files       = fs.GetFiles("");
        }
Пример #33
0
 public void SimpleVhdFat()
 {
     using (Disk disk = Disk.InitializeDynamic(new MemoryStream(), Ownership.Dispose, 16 * 1024 * 1024))
     {
         BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsFat);
         using (FatFileSystem fs = FatFileSystem.FormatPartition(disk, 0, null))
         {
             fs.CreateDirectory("Foo");
         }
     }
 }
Пример #34
0
        protected virtual void InitializeFileSystems()
        {
            for (int i = 0; i < mPartitions.Count; i++)
            {
                string xRootPath = string.Concat(i, VolumeSeparatorChar, DirectorySeparatorChar);
                Cosmos.System.FileSystem.FileSystem xFileSystem = null;
                switch (Cosmos.System.FileSystem.FileSystem.GetFileSystemType(mPartitions[i]))
                {
                case FileSystemType.FAT:
                    xFileSystem = new FatFileSystem(mPartitions[i]);
                    mFileSystems.Add(new KVP <string, Cosmos.System.FileSystem.FileSystem>(xRootPath, xFileSystem));
                    break;

                default:
                    FatHelpers.Debug("Unknown filesystem type!");
                    return;
                }

                //global::System.Console.Write("i = ");
                //global::System.Console.WriteLine(i.ToString());
                //global::System.Console.Write("mFileSystems.Count = ");
                //global::System.Console.WriteLine(mFileSystems.Count);
                var xEntry = mFileSystems[i];
                if (xEntry.Key == xRootPath)
                {
                    var xFatFS = (FatFileSystem)xFileSystem;
                    FatHelpers.Debug("-------File System--------");
                    FatHelpers.Debug("Bytes per Cluster: " + xFatFS.BytesPerCluster);
                    FatHelpers.Debug("Bytes per Sector: " + xFatFS.BytesPerSector);
                    FatHelpers.Debug("Cluster Count: " + xFatFS.ClusterCount);
                    FatHelpers.Debug("Data Sector: " + xFatFS.DataSector);
                    FatHelpers.Debug("Data Sector Count: " + xFatFS.DataSectorCount);
                    FatHelpers.Debug("FAT Sector Count: " + xFatFS.FatSectorCount);
                    FatHelpers.Debug("FAT Type: " + xFatFS.FatType);
                    FatHelpers.Debug("Number of FATS: " + xFatFS.NumberOfFATs);
                    FatHelpers.Debug("Reserved Sector Count: " + xFatFS.ReservedSectorCount);
                    FatHelpers.Debug("Root Cluster: " + xFatFS.RootCluster);
                    FatHelpers.Debug("Root Entry Count: " + xFatFS.RootEntryCount);
                    FatHelpers.Debug("Root Sector: " + xFatFS.RootSector);
                    FatHelpers.Debug("Root Sector Count: " + xFatFS.RootSectorCount);
                    FatHelpers.Debug("Sectors per Cluster: " + xFatFS.SectorsPerCluster);
                    FatHelpers.Debug("Total Sector Count: " + xFatFS.TotalSectorCount);

                    //Console.WriteLine();
                    //Console.WriteLine("Mapping Drive C...");
                    //FatFileSystem.AddMapping("C", mFileSystem);
                    //SentinelKernel.System.Filesystem.FAT.Listing.FatDirectory dir = new Sys.Filesystem.FAT.Listing.FatDirectory(mFileSystem, "Sentinel");
                }
                else
                {
                    FatHelpers.Debug("No filesystem found.");
                }
            }
        }
Пример #35
0
        /// <summary>
        /// Initializes a new instance of the Directory class.  Use this constructor to represent non-root directories.
        /// </summary>
        /// <param name="parent">The parent directory</param>
        /// <param name="parentId">The identity of the entry representing this directory in the parent</param>
        internal Directory(Directory parent, long parentId)
        {
            _fileSystem = parent._fileSystem;
            _parent     = parent;
            _parentId   = parentId;

            DirectoryEntry dirEntry = ParentsChildEntry;

            _dirStream = new ClusterStream(_fileSystem, FileAccess.ReadWrite, dirEntry.FirstCluster, uint.MaxValue);

            LoadEntries();
        }
Пример #36
0
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aFullPath,
            string aName,
            ulong aFirstCluster)
            : base(aFileSystem, aParent, aFullPath, aName, 0, DirectoryEntryTypeEnum.Directory)
        {
            if (aFirstCluster < aFileSystem.RootCluster)
            {
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = 0;
        }
Пример #37
0
        public FatDirectoryEntry(
            FatFileSystem aFileSystem,
            FatDirectoryEntry aParent,
            string aFullPath,
            string aName,
            ulong aFirstCluster)
            : base(aFileSystem, aParent, aFullPath, aName, 0, DirectoryEntryTypeEnum.Directory)
        {
            Global.mFileSystemDebugger.SendInternal("FatDirectoryEntry.ctor");

            if (aFirstCluster < 2)
            {
                Global.mFileSystemDebugger.SendInternal("aFirstCluster is out of range.");
                throw new ArgumentOutOfRangeException(nameof(aFirstCluster));
            }

            mFirstClusterNum = aFirstCluster;
            mEntryHeaderDataOffset = 0;
        }
Пример #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VfsFileSystem"/> class.
 /// </summary>
 /// <param name="fat">The fat.</param>
 public VfsFileSystem(FatFileSystem fat)
 {
     Fat = fat;
 }
Пример #39
0
 // Size is UInt32 because FAT doesn't support bigger.
 // Dont change to UInt64
 public FatFile(FatFileSystem aFileSystem, string aName, UInt32 aSize, UInt64 aFirstCluster)
   : base(aFileSystem, aName, aSize) {
   FileSystem = aFileSystem;
   FirstClusterNum = aFirstCluster;
 }
Пример #40
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FatFileStream"/> class.
 /// </summary>
 /// <param name="fs">The fs.</param>
 /// <param name="location">The location.</param>
 public FatFileStream(FatFileSystem fs, FatFileLocation location)
     : this(fs, location.FirstCluster, location.DirectorySector, location.DirectorySectorIndex)
 {
 }
Пример #41
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FatFileStream"/> class.
        /// </summary>
        /// <param name="fs">The fs.</param>
        /// <param name="startCluster">The start cluster.</param>
        /// <param name="directorySector">The directory sector.</param>
        /// <param name="directorySectorIndex">Index of the directory sector.</param>
        public FatFileStream(FatFileSystem fs, uint startCluster, uint directorySector, uint directorySectorIndex)
        {
            this.fs = fs;
            this.clusterSize = fs.ClusterSizeInBytes;
            this.data = new byte[clusterSize];
            this.startCluster = startCluster;
            this.directorySector = directorySector;
            this.directorySectorIndex = directorySectorIndex;
            this.read = true;
            this.write = false;
            this.position = 0;
            this.dirty = false;

            this.nthCluster = System.UInt32.MaxValue; // Not positioned yet

            this.lengthOnDisk = fs.GetFileSize(directorySector, directorySectorIndex);
            this.length = this.lengthOnDisk;

            currentCluster = 0;
        }
Пример #42
0
 // Size is UInt32 because FAT doesn't support bigger.
 // Dont change to UInt64
 public FatFile(FatFileSystem aFileSystem, string aName, UInt32 aSize, UInt64 aFirstCluster, FatDirectory baseDirectory)
     : base(aFileSystem, aName, aSize, baseDirectory)
 {
     FileSystem = aFileSystem;
     FirstClusterNum = aFirstCluster;
 }