コード例 #1
0
        public void Write(int index, byte[] data)
        {
            // Make sure this is a file
            if (!IsFile)
            {
                throw new Exception("Must write to a file!");
            }

            // Load the cache of blocks for the file
            LoadBlocks();

            // Grow the cached blocks if needed
            int finalLength = Math.Max(FileLength, index + data.Length);

            VirtualBlock.ExtendBlocks(drive, blocks, FileLength, finalLength);

            // Write the bytes to the cache
            VirtualBlock.WriteBlockData(drive, blocks, index, data);

            // Flush the cache of blocks
            CommitBlocks();

            // Adjust file size as needed
            if (finalLength > FileLength)
            {
                (sector as FILE_NODE).FileSize = index + data.Length;
                drive.Disk.WriteSector(nodeSector, sector.RawBytes);
            }
        }
コード例 #2
0
        public void Write(int index, byte[] data)
        {
            if (!IsFile)
            {
                throw new Exception("Must be a file to write bytes!");
            }

            // Make sure the cache is filled!
            LoadBlocks();

            // Extend the blocks if necessarry
            int initialFileLength = FileLength;
            int finalFileLength   = Math.Max(index + data.Length, initialFileLength);

            VirtualBlock.ExtendBlocks(drive, blocks, initialFileLength, finalFileLength);

            // Write the data to the blocks
            VirtualBlock.WriteBlockData(drive, blocks, index, data);


            //Write the blocks
            CommitBlocks();

            // Update file length in file node sector
            // Make sure to incease the file length as needed
            if (finalFileLength > initialFileLength)
            {
                (sector as FILE_NODE).FileSize = finalFileLength;
                drive.Disk.WriteSector(nodeSector, sector.RawBytes);
            }
        }
コード例 #3
0
        public void Write(int index, byte[] data)
        {
            //writes data bytes to the file starting at the index byte

            //fill cache by read current data from disk for this file
            LoadBlocks();

            //if data to be writen is beyond the end of the current number of blocks, extend blocks
            int currentFileLength = FileLength;
            int newFileLength     = Math.Max(currentFileLength, index + data.Length);

            VirtualBlock.ExtendBlocks(drive, blocks, currentFileLength, newFileLength);

            //copy data from cache to blocks
            VirtualBlock.WriteBlockData(drive, blocks, index, data);

            //commit cache back to disk
            CommitBlocks();

            if (newFileLength > currentFileLength)
            {
                (sector as FILE_NODE).FileSize = newFileLength;
                drive.Disk.WriteSector(nodeSector, sector.RawBytes);
            }
        }