Exemplo n.º 1
0
        /// <summary>
        /// Gets the last NoobFSBlock of the directory
        /// </summary>
        private NoobFSBlock GetBlockToEdit()
        {
            NoobFSBlock ret = _StartBlock;

            while (ret.NextBlock != 0)
            {
                ret = NoobFSBlock.Read(_StartBlock.Partition, _StartBlock.NextBlock);
            }
            if (ret.BlockNumber == _StartBlock.BlockNumber)
            {
                ret                   = NoobFSBlock.GetFreeBlock(part);
                ret.Used              = true;
                ret.ContentSize       = 0;
                ret.NextBlock         = 0;
                _StartBlock.NextBlock = ret.BlockNumber;
                NoobFSBlock.Write(part, _StartBlock);
                NoobFSBlock.Write(part, ret);
            }
            if (part.NewBlockArray(1).Length - ret.ContentSize < 12)
            {
                NoobFSBlock b = NoobFSBlock.GetFreeBlock(part);
                if (b == null)
                {
                    return(null);
                }
                ret.NextBlock = b.BlockNumber;
                NoobFSBlock.Write(part, ret);
                b.Used = true;
                ret    = b;
            }
            return(ret);
        }
        /// <summary>
        /// Writes all the specified Bytes into the file
        /// </summary>
        /// <param name="Data">The array Byte to write into file</param>
        public void WriteAllBytes(Byte[] Data)
        {
            if (_StartBlock.NextBlock != 0)
            {
                NoobFileSystem.ClearBlocks(_StartBlock);
                _StartBlock.NextBlock = 0;
                NoobFSBlock.Write(NoobFileSystem.mFS.Partition, _StartBlock);
            }
            int         index = 0;
            NoobFSBlock curb  = NoobFSBlock.GetFreeBlock(NoobFileSystem.mFS.Partition);

            _StartBlock.NextBlock = curb.BlockNumber;
            NoobFSBlock.Write(part, _StartBlock);
            do
            {
                Byte[] arr = new Byte[NoobFSBlock.MaxBlockContentSize];
                index        = Utils.CopyByteToByte(Data, index, arr, 0, arr.Length);
                curb.Used    = true;
                curb.Content = arr;
                if (index != Data.Length)
                {
                    NoobFSBlock b = NoobFSBlock.GetFreeBlock(NoobFileSystem.mFS.Partition);
                    curb.NextBlock   = b.BlockNumber;
                    curb.ContentSize = (uint)arr.Length;
                    NoobFSBlock.Write(NoobFileSystem.mFS.Partition, curb);
                    curb = b;
                }
                else
                {
                    curb.ContentSize = (uint)(Data.Length % arr.Length);
                    NoobFSBlock.Write(NoobFileSystem.mFS.Partition, curb);
                }
            }while (index != Data.Length);
            EditEntryInfo(EntryInfoPosition.DateTimeModified, Environment.DateTime.Now.TimeStamp);
            EditEntryInfo(EntryInfoPosition.DateTimeLastAccess, Environment.DateTime.Now.TimeStamp);
        }
 /// <summary>
 /// Creates a new NoobEntry in the current directory. Uses a random Block.
 /// </summary>
 /// <param name="p">The partition where to create the new NoobEntry</param>
 /// <param name="name">The new NoobEntry's name</param>
 protected static NoobFSBlock CreateEntry(Partition p, String name)
 {
     return(CreateEntry(p, NoobFSBlock.GetFreeBlock(p), name));
 }