예제 #1
0
 private void PageOftBuffer(OftEntry entry, Descriptor descriptor, int newBlockIndex)
 {
     if(entry.FileBlock != -1)
         disk.WriteBlock(descriptor.DiskMap[entry.FileBlock], entry.Buffer);
     disk.ReadBlock(descriptor.DiskMap[entry.FileBlock = newBlockIndex], entry.Buffer);
 }
예제 #2
0
        /// <summary>
        /// Resets the file system's state to its initial value.
        /// </summary>
        public void Init()
        {
            disk = new Disk(BlockCount, BlockSize);
            oft = new OftEntry[MaxOpenFiles];
            for (int i = 0; i < MaxOpenFiles; i++)
                oft[i] = new OftEntry();

            // Mark the blocks needed for the bitmap and
            // the file descriptors as reserved.
            for (int i = 0; i < BitmapBlockCount + DescriptorBlockCount; i++)
                SetBitmapBit(i, true);

            // Initialize all descriptors to blank.
            var descriptor = new Descriptor();
            for (int i = 1; i < DescriptorCount; i++)
                WriteDescriptor(i, descriptor);

            // Initialize the directory descriptor.
            descriptor.Length = 0;
            WriteDescriptor(0, descriptor);

            // Initialize directory's oft entry.
            var oftDir = oft[0];
            oftDir.DescriptorIndex = 0;

            // Initialize the directory file.
            var dirEntry = new DirEntry();
            for (int i = 1; i < DirectoryEntryCount; i++)
                WriteDirEntry(i, dirEntry);

            // Create the directory entry which describes the
            // directory itself.
            dirEntry.DescriptorIndex = 0;
            dirEntry.Name[0] = (byte)'d';
            dirEntry.Name[1] = (byte)'i';
            dirEntry.Name[2] = (byte)'r';
            WriteDirEntry(0, dirEntry);

            var dirDesc = ReadDescriptor(0);
        }