Example #1
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];
        }
Example #2
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();
        }
Example #3
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;
        }
Example #4
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();
        }
Example #5
0
        static void Main(string[] args)
        {
            var options = new Options();
            if (!Parser.Default.ParseArguments(args, options))
            {
                return;
            }

            //tools
            var dd = @"Tools\dd.exe";
            var grub = @"Tools\boot\";
            var myos = @"Tools\myos.img";
            var grubstage1 = @"Tools\boot\stage1";

            //stuff we need
            var img = options.OutPutFile;
            var folder = options.inputfolder;

            //create file
            // StartProcces(dd, "bs=512 if=" + grubstage1 + " of=" + img + "count=2880", "");
            File.Copy(myos, img);
            using (FileStream fs = File.Open(img, FileMode.Open))
            {
                using (FatFileSystem floppy = new FatFileSystem(fs))
                {
                    foreach (var i in Directory.GetFiles(folder))
                    {
                        using (Stream s = floppy.OpenFile(new FileInfo(i).Name, FileMode.Create))
                        {
                            var x = File.ReadAllBytes(i);
                            s.Write(x, 0, x.Length);
                        }
                    }
                }
            }

            //dd if=./Bin/boot.bin of=./Bin/bootimage.ima
        }
        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();
            }
        }
        public void FormatPartition()
        {
            MemoryStream ms = new MemoryStream();

            Geometry g = Geometry.FromCapacity(1024 * 1024 * 32);
            FatFileSystem fs = FatFileSystem.FormatPartition(ms, "KBPARTITION", g, 0, (int)g.TotalSectorsLong, 13);

            fs.CreateDirectory(@"DIRB\DIRC");

            FatFileSystem fs2 = new FatFileSystem(ms);
            Assert.AreEqual(1, fs2.Root.GetDirectories().Length);
        }