Esempio n. 1
0
        public bool CreateDirectory(string name)
        {
            if (name.Length > 16320)
            {
                return(false);
            }

            //dir names must be guid
            foreach (var entry in IndexAria)
            {
                if (entry is DirectoryEntry de)
                {
                    if (de.Name == name)
                    {
                        return(false);
                    }
                }
            }

            //add it
            IndexAria.Insert(IndexAria.Count - 1, new DirectoryEntry
            {
                TimeStamp = 0,
                Name      = name
            });
            Save();

            return(true);
        }
Esempio n. 2
0
        public bool WriteAllBytes(string filePath, byte[] data)
        {
            if (filePath.Length > 16320)
            {
                return(false);
            }

            FileEntry fileEntry = null;

            //file names must be guid
            foreach (var entry in IndexAria)
            {
                if (entry is FileEntry fe)
                {
                    if (fe.Name == filePath)
                    {
                        fileEntry = fe;
                        break;
                    }
                }
            }

            if (fileEntry == null)
            {
                fileEntry = new FileEntry
                {
                    StartingBlock = SuperBlock.DataSizeInBlocks + SuperBlock.TotalReservedBlocks,
                    EndingBlock   = (SuperBlock.DataSizeInBlocks + SuperBlock.TotalReservedBlocks) +
                                    (data.Length / BlockDevice.BlockSize) + 1,
                    Length    = data.Length,
                    Name      = filePath,
                    TimeStamp = 0
                };

                SuperBlock.DataSizeInBlocks += fileEntry.EndingBlock - fileEntry.StartingBlock;

                //add it
                IndexAria.Insert(IndexAria.Count - 1, fileEntry);
            }

            //write data
            var bl = fileEntry.EndingBlock - fileEntry.StartingBlock;

            var buf = new byte[BlockDevice.BlockSize];

            long c = 0;

            for (int i = 0; i < bl - 1; i++)
            {
                Array.Copy(data, i * BlockDevice.BlockSize, buf, 0, BlockDevice.BlockSize);
                c += BlockDevice.BlockSize;
                BlockDevice.WriteBlock(fileEntry.StartingBlock + i, buf);
            }


            Array.Copy(data, c, buf, 0, data.Length - c);
            BlockDevice.WriteBlock(fileEntry.StartingBlock + (bl - 1), buf);

            Save();
            return(true);
        }